【问题标题】:WordPress custom post type archive widget to display only CPTWordPress 自定义帖子类型存档小部件仅显示 CPT
【发布时间】:2017-07-07 17:31:40
【问题描述】:

我目前有一个 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');

上面的 sn-p 现在返回我的 CPT 的档案,但它也包括正常的帖子

如何只显示 CPT?

【问题讨论】:

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

标签: php wordpress wordpress-theming


【解决方案1】:

您正在将您的 CPT 添加到列表中并使用 IN 子句,如果您只想显示您的 CPT,请仅将 WHERE 子句替换为您的 CPT,如下所示:

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-10-30
  • 2012-08-31
  • 1970-01-01
  • 1970-01-01
  • 2016-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多