2015-02-12 58 views
2

我正在註冊多個自定義帖子類型。一個是'新聞',第二個是讓我們說'通知'。我與註冊了這兩個(和許多其他人):當請求多個帖子類型時,WP_Query將不會返回其中一個自定義帖子類型

消息:

$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); 

}

如果我試圖讓比如 '新聞' 和'post'post type(或'news'and'event'etc)like this

​​

它會做它應該做的:獲取post_type數組參數中給出的所有類型的帖子。

但是,當我試圖讓任何類型的'通知'發佈類型,它不會返回'通知'發佈類型。例如我想:

'post_type'=>陣列( '新聞', '後'),//新聞和職位獲得返回

'post_type'=>陣列( '新聞',「通知'),//消息得到恢復,但不會收到通知

'post_type'=>陣列(' 後」, '通知'),//只有職位獲得返回

如果只通過 '通知'帖子類型我得到的帖子返回,因爲我應該:

「post_type」 =>數組(「通知」),//我得到所有通知

爲什麼不會我接收類型「通知」的任何後是否有任何其它類型的後存在於post_type數組?這裏一定有些可笑的東西。

唯一不同的註冊消息和通知時是「can_export」和「分類」,但不是它(試過評論了這一點通知)

謝謝

UPDATE

好,所以我認爲我有罪魁禍首:Polylang插件。如果停用,則它應該可以正常工作。有任何想法嗎?!

+0

您是否檢查過'$ labels'是''notification''帖子類型的有效數組?'不確定這在所有方面都是重要的。 – rnevius 2015-02-12 08:17:27

+0

我很肯定它是這樣的:它和「新聞」和其他帖子類型一樣 – trainoasis 2015-02-12 08:20:32

+0

只是一個想法,你可能與核心術語有衝突。您是否嘗試將通知重命名爲通知或其他內容。請記住在更改後重新刷新重寫規則 – 2015-02-12 08:34:01

回答

1

好的,我明白了。像預期的那樣絕對荒謬。

其中一個自定義帖子類型未在Polylang設置中進行翻譯和檢查,因爲它是在插件配置後添加的。

設置 - >語言 - >設置 - >自定義文章類型

該死。

相關問題