2017-07-07 74 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

相关问题