我目前有一个CPT变更日志,在我的自定义侧边栏上,我只想显示此CPT的存档,而不是所有其他帖子的存档。
例如 :
2017年1月->应该仅显示CPT变更日志帖子,依此类推。
到目前为止,这是我尝试过的:
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?
您将CPT添加到列表中并使用一个IN
子句,如果您只想显示CPT,则仅用CPT替换该WHERE
子句,如下所示:
$where = str_replace("post_type = 'post'", "post_type = 'changelog'", $where);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句