duangou2028 2016-08-26 18:03
浏览 113

Wordpress pre_get_posts钩子在Wordpress“页面”帖子类型上不起作用?

I have a Wordpress "page" (post type), with slug "/mypage". On the page (using template page-mypage.php) I'm trying to show a custom list of posts, so I thought I'd tap into the "pre_get_posts" filter to do that. Inside the template page-mypage.php I do something like the following to try and filter the output of the Main Loop:

function getuserfavs($query){
  if ($query->is_main_query()){
        $query->set('post_type', 'post');
        $query->set('post__in', array(130, 128));
  }
}

add_action('pre_get_posts', 'getuserfavs');

That doesn't work, however, and all I get when viewing "/mypage" is a 404 page not found template. The Main loop if I look into it isn't altered either. Can anyone explain why this is so? Am I missing something in terms of how 'pre_get_posts' should be used?

Thanks,

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用