【发布时间】:2019-10-06 14:35:26
【问题描述】:
我需要从我的 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 的相应自定义字段?
【问题讨论】: