如何解决如何正确确定posttype是否在wordpress多站点的给定博客中处于活动状态
如果我注册这样的帖子类型,例如:
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 举报,一经查实,本站将立刻删除。