Support » Fixing WordPress » Custom Post Types Paginated Category Archive = 404

  • Resolved Mike



    I’ve been struggling with this problem a while now so I’m giving in and asking for assistance.

    So, I have a custom post type called ‘product’ – this custom post type is set up to use the ‘category’ taxonomy.

    The first page of the category archive works fine – I have placed:

    global $wp_query;
    		array('post_type' => 'product'),

    at the top of category.php in the template. When you go to page 2 however, it gives a 404.

    From what I can tell this is because the query functions/template loader are making it a 404 before the post_type rule is seen because its not finding any ‘posts’ on page 2 of the archive.

    I’ve tried adding hooks into functions.php to try to get the post_type recognised earlier with no success.

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Mike


    For anyone else, this is how I had to fix it:

    function init_category($request) {
    	$vars = $request->query_vars;
    	if (is_category() && !is_category('Blog') && !array_key_exists('post_type', $vars)) :
    		$vars = array_merge(
    			array('post_type' => 'any')
    		$request->query_vars = $vars;
    	return $request;
    add_filter('pre_get_posts', 'init_category');


    Thanks a lot! Been puling out my hair for a couple of hours now…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Types Paginated Category Archive = 404’ is closed to new replies.