php - 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 的单个帖子吗?
谢谢
解决方案
推荐阅读
- python - 如何打印此列表的所有组合?
- java - 从 db.properties 文件加载属性时出现异常
- java - ¿ 如何检查 int 变量的字符数?
- javascript - 我们可以在 JS 文件的顶部写“use strict”,它会验证所有函数和语句吗?
- python - Django Migration InternalError 1054 未知列
- c - 使用 SAT 求解器打印 N-Queens 问题的所有解
- vue.js - 将 Axios 调用的结果添加到 State
- javascript - 带有数据表的嵌套表
- python - MySQL/python 字符集问题
- r - 从第三次观察开始,在 R 中进行黄土曲线拟合