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,