作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从 WordPress 外部的数据库获取自定义字段;我可以获取帖子,但我不知道如何获取它们各自的帖子元。
function seconddb() {
global $seconddb;
$args = array('post_type' => 'post',
'show_posts' => '10',
'paged' => $paged
);
$the_query = new WP_Query($args);
$seconddb = new wpdb('aaa', 'bbb', 'ccc', 'ddd');
$rows = $seconddb->get_results("SELECT ID FROM K1nG_posts");
foreach ($rows as $obj) :
echo $obj->ID;
endforeach;
// Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo get_post_meta( get_the_ID(), 'post', true);
}
}
}
add_action('init', 'seconddb');
任何人都可以帮助我获取在 WordPress 数据库中找到 post_meta 的相应自定义字段吗?
最佳答案
尝试看看此 SO 和 codex.wordpress 链接是否有助于解决您的问题
https://developer.wordpress.org/reference/functions/get_post_meta/
https://codex.wordpress.org/Function_Reference/post_meta_Function_Examples
Display all post meta keys and meta values of the same post ID in wordpress
关于php - 如何从 WordPress 中的另一个数据库获取帖子元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58258292/
我是一名优秀的程序员,十分优秀!