我正在注册多个自定义帖子类型。一是“新闻”,二是“通知”。我正在注册这两个(以及许多其他):
新闻:
$labels = .. // leaving this blank for SO, shouldn't be of importance
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'news' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' )
);
register_post_type( 'news', $args );
通知:
$labels = .. // leaving this blank for SO, shouldn't be of importance
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'notification' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'revisions' ),
'can_export' => true,
'taxonomies' => array('employee'),
);
register_post_type( 'notification', $args );
}
如果我尝试获取例如“新闻”和“帖子”帖子类型(或“新闻”和“事件”等),就像这样
$args = array(
'post_type' => array('news','post'),
);
$the_query = new WP_Query( $args );
它将做它应该做的事情:获取 post_type 数组参数中给定类型的所有帖子。
但是,当我尝试获取任何带有“通知”帖子类型的帖子类型时,它不会返回“通知”帖子类型。我尝试过的例子:
'post_type' => array('news','post'), // 返回新闻和帖子
'post_type' => array('news','notification'), // 返回新闻,但不返回通知
'post_type' => array('post','notification'), // 仅返回帖子
仅传递“通知”帖子类型时,我会按预期返回帖子:
'post_type' => array('notification'), // 我收到所有通知
如果 post_type 数组中存在任何其他帖子类型,为什么我不会收到任何类型为“通知”的帖子? 一定有一些明显可笑的东西我在这里丢失了。
注册新闻和通知时的唯一区别是“can_export”和“taxonomies”,但事实并非如此(尝试注释掉通知)
谢谢你
更新
好吧,我认为罪魁祸首是:Polylang Plugin。如果停用,这将按其应有的方式工作。有什么想法吗?!
好的,我明白了。正如预期的那样,绝对荒谬。
其中一种自定义帖子类型未在 Polylang 设置中进行翻译和检查,因为它是在配置插件后添加的。
设置->语言->设置->自定义帖子类型
该死的。