Pre_get_posts Gives 404 on Custom Post Type

Changing a query for the page post type via pre_get_posts is a bit tricky, and maybe not worth the potential issues involved. If you inspect the generated SQL, it’s looking for your requested pagename in the question post type, which is why you get the 404.

The solution is to delete the page, so WordPress will load a post type archive by default, or keep the page and use WP_Query within the template to load the custom posts.

Leave a Comment