首页 > 解决方案 > Wordpress - 显示来自另一个 WP 数据库的单个 CPT

问题描述

我有 2 个带有工作板的 WP 站点(在 functions.php 以及 archive-jobboard.php 和 single-jobboard.php 中创建的 CPT):

到目前为止我所做的: - 尝试并成功地将帖子从父站点检索到具有特定连接数据库和查询的子站点:

<?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 的单个帖子吗?

谢谢

标签: phpwordpress

解决方案


推荐阅读