我创建了一个自定义帖子类型(称之为“我的帖子类型”)archive-my-post-type.php 显示所有自定义帖子类型的页面none of custom post types are showing up.to show in Recent Posts 还有this article 在WP Stack上显示我可以使用pre_get_posts
将我的自定义帖子类型添加到最近的帖子(侧栏)
我做了一些调查pre_get_posts
据我所知。。。
pre_get_posts
用于更改the main loop.
Identifying Target Queries
使用pre\\u get\\u posts时,请注意您正在更改的查询。一个有用的工具是\\u main\\u query(),它可以帮助您确保要修改的查询is only the main query.标题中的短语“target querys”(目标查询)在我看来似乎意味着can “target”我要修改的查询code from stack 而且does not use is_main_query()
. NOT “主查询”的一部分two queries...
此查询位于整个页面上方(后面是我的所有自定义帖子)。。。
\'SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = \'press-release\' AND (wp_posts.post_status = \'publish\') ORDER BY wp_posts.post_date DESC LIMIT 0, 10\'
另一个查询在上面the sidebar...\'SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = \'post\' AND (wp_posts.post_status = \'publish\') ORDER BY wp_posts.post_date DESC LIMIT 0, 5\'
我想将我的自定义帖子类型添加到this 查询我是否可以(也应该)使用pre\\u get\\u posts来实现这一点?
我是个新手,所以我真的希望这个问题有意义。