Wordpress-从另一个WP数据库显示单个CPT

时间:2018-09-03 08:56:24

标签: php wordpress

我有2个带有工作板的WP网站(CPT是在functions.php中创建的,还有archive-jobboard.php和single-jobboard.php):

  • 父站点:所有职位发布都在此处输入并显示在前端

  • 子站点:我希望在前端显示具有特定术语的职位。

到目前为止,我所做的是: -尝试并成功通过特定的连接数据库和查询将帖子从父网站撤回到子网站中:

<?php global $wpdb; 
$wpdb_backup = $wpdb;
$wpdb = connect_to_site_DB();

$sitenews = new WP_Query(array(
'post_type' => 'jobboard',
'tax_query' =>(array('taxonomy'=> 'entreprise','field' => 'slug',terms =>'the_company_name')),
'post_status' => 'publish',
'orderby' => 'menu_order',
'order' => 'ASC',
'no_found_rows' => true,
'update_post_term_cache' => false, 
'update_post_meta_cache' => false, 
'ignore_sticky_posts' => true,
'nopaging' => true,
'posts_per_page' => 5,
));

if(!empty($sitenews->posts)) {
$counter_posts = 1;
    foreach ($sitenews->posts as &$post) 

        the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); 
    $counter_posts++;
}

$wpdb = $wpdb_backup; ?>

现在我要显示单个帖子。单击存档页面中的链接后,我得到一个404。

是否甚至可以显示来自另一个WP的单个帖子?

谢谢

0 个答案:

没有答案