问题描述
如果我注册这样的帖子类型,例如:
function setup_post_type() {
$args = array(
'public' => true,'label' => __( 'Recipe','textdomain' ),'menu_icon' => 'dashicons-book',);
// Should only be active in a given blog
if( get_current_blog_id() === 14 ) {
register_post_type( 'recipe',$args );
}
}
add_action( 'init','setup_post_type' );
它仅在ID为14的给定博客的后端中可用。但是,当尝试确定该帖子类型是否在另一个博客中处于活动状态时(例如,为帖子归档建立hreflang链接),您将获得以下内容:
因此,假设您访问ID为14的博客:
var_dump(get_current_blog_id()); // 14
var_dump(post_type_exists('recipe')); // true
switch_to_blog(15);
var_dump(post_type_exists('recipe')); // true
restore_current_blog();
但是,如果您访问ID为15的博客,则会得到以下信息:
var_dump(get_current_blog_id()); // 15
var_dump(post_type_exists('recipe')); // false
switch_to_blog(14);
var_dump(post_type_exists('recipe')); // false
restore_current_blog();
由于帖子是在wordpress的init
钩中注册的,因此根据您开始加载网站的位置,这些帖子现在可用,并且不会重新评估依赖关系。
有没有办法正确确定其他博客上的帖子类型?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)