2017-07-07 99 views
2

我目前有一個CPT更改日誌,並且在我的自定義側欄上我想只顯示此CPT的檔案,而不是所有其他帖子。WordPress自定義帖子類型存檔窗口小部件只顯示CPT

例如:

2017年1 - >應只顯示CPT的changelog後 等。

這是我迄今爲止嘗試:

function custom_changelog_getarchives_where($where) 
{ 
    $where = str_replace("post_type = 'post'", "post_type IN ('post', 
    'changelog')", $where); 

    return $where; 
} 

add_filter('getarchives_where', 'custom_changelog_getarchives_where'); 

上面的代碼現在返回我的CPT的檔案,但它也有正常的崗位以及

我怎麼只顯示CPT?

+0

'$ =哪裏str_replace(「post_type ='post'」,「post_type ='changelog'」,$ where);' – naththedeveloper

回答

1

您要添加的CPT的列表,並使用IN條款,如果你只是想顯示你的CPT,只有你CPT更換WHERE條款,如:

$where = str_replace("post_type = 'post'", "post_type = 'changelog'", $where); 
+0

啊對了,謝謝! – highFlyingDodo

相關問題