• Resolved Mike

    (@jolley_small)


    Hello,

    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;
    	query_posts(
    	array_merge(
    		array('post_type' => 'product'),
    		$wp_query->query
    	)
    );

    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)
  • Thread Starter Mike

    (@jolley_small)

    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(
    			$vars,
    			array('post_type' => 'any')
    		);
    		$request->query_vars = $vars;
    	endif;
    	return $request;
    }
    add_filter('pre_get_posts', 'init_category');
    Robert

    (@robertgrinde)

    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.