Support » Fixing WordPress » Custom Types & Category Pagination 404

  • Hi guys,

    I’m in Custom Type hell right now… I’m using both custom types and custom taxonomies and I’ve had to do so many hacks to make permalinks work properly that I’m ready to jump off a … thing.

    Anyhow, it seems as though pagination was the final straw, and I’m getting 404’s on anything beyond page 1. So /category/news/page/1 works but /category/news/page/2 gives a 404. What’s the deal? This is a category page, but I’m not catching anything in category.php. Somehow it’s bypassing it and going straight to the 404…

    So my question would be answered by one of two things:

    1) Where is it checking for content and failing (so perhaps I can hack it)?
    2) Anyone else have and been able to resolve this issue?

    Thanks so much guys.

Viewing 15 replies - 1 through 15 (of 23 total)
  • If you’re attempting to use category as the rewrite slug in your custom taxonomy it will likely conflicting with the WordPress native category rewrite rules.

    If the above is true, try changing it for something else(even if just for a few minutes just to see if it resolves the issue), remembering to visit the permalink page after any changes to taxonomy registration code(doing so will regenerate the rewrite rules).

    Hi Mark,

    Thanks for the reply! I don’t have a news taxonomy, so that’s not the case. And my news page has a permalink of “news-page” so I don’t think that’s conflicting either.

    Any ideas of what else might be conflicting? Or where I can dink around in WordPress’s files to catch the request before it turns into a 404?

    Paste of a copy of your rewrite rules into a pastebin and report the link back(probably a conflict between rules)..

    To print out the permalinks run the following code in one of your template files.

    <?php print '<pre>';print_r( get_option('rewrite_rules') );print '</pre>'; ?>

    Remove the code afterwards(you obviously won’t want that mess of data displaying on your pages).

    If you can’t follow any of the above, please say so and i’ll explain in more detail… 😉

    Hi Mark,

    The degree to which my install is fudged has led me to decide to start over… I made a number of mistakes including giving my custom type slugs the same names as categories (and at one point pages). I also dinked with Custom Taxonomies and Custom Types plugins, both of which are apparently problematic compared to running register_post_type and register_taxonomy from what I’ve read and experienced.

    If you’re curious about the quagmire of my site, here’s the pastie:
    http://wordpress.pastebin.com/94ZFgPXD

    Do you see conflicts in there? I’m not exactly sure what to look for…

    And thanks again for your help!

    What is your permalink structure set to?

    /%category%/%post_name%

    So I did a fresh install, and the same problem exists.

    And I’ve narrowed it down to something very specific.

    Pagination on category pages DOES NOT WORK if you declare a post_type of anything besides ‘post’. And if you include multiple post_type’s, pagination only calculates based on the number of ‘post’ typed objects. So for example if you set the posts_per_page to 4 and have 8 posts type ‘post’ and 2 posts type ‘news_type’, you will have the option to paginate between 3 pages but only the first two will work. The third will 404.

    I’ve verified this in a bit of testing. Do you know how I can dink with the WordPress core to get this up and running? I need this website to be alive in a week and this bug is sucky.

    Thanks!

    I did some more testing and … I just don’t get it.

    There was one instance where a category page with a single post_type could paginate… but on a different category page a different post_type could not. I’m still looking into it.

    What is (fortunately or unfortunately) consistent is that whatever decides to 404 or give you a category page does not add the multiple post_type’s together.

    Ok first step, go to the permalinks page, and set one of the other permalink structures, anything that’s not default(off) or custom, and then see how your various pages work(Month and Name, Day and Name would be two examples).

    Your taxonomy and custom post type URLs will not change at all as a result, the bulk of the permalinks deal with posts and the default taxonomies, anything else gets it’s own form of permalink(which you can also control inside your type or taxonomy registration code).

    That one change should resolve most(if not all) of your 404 problems, but if not then i’d suggest testing with the Default theme(if you’re not already).

    Hi Mark,

    I switched to the default theme and added a custom query to the archive.php so it’d display post types aside from ‘post’… and I’m still getting 404’s every time I try to paginate.

    As for permalinks, I tried all of the options (besides default) and I still got 404’s.

    Have you ever tried to paginate custom type objects through a category page? It works from a page.php variation…

    Here’s my query if you’re curious.

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$args = array(
    			'post_type' => array('test_type', 'press_type', 'news_type'),
    			'category_name' => $category,
    			'posts_per_page' => 12,
    			'paged' => $paged
    			);
    
    		query_posts($args);
    if (have_posts()) :

    Do your custom post type’s have the category taxonomy enabled for them? Or perhaps an easier question is, are you setting the taxonomies parameter in your post type registration code, or alternatively calling register_taxonomy_for_object_type?

    See the taxonomies parameter.
    http://codex.wordpress.org/Function_Reference/register_post_type

    And additionally.
    http://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type

    Yup, I have it defined in the register_post_type(). You can see how I do it below…

    register_post_type('press_type', array(
    	    'label' => __('Press'),
    	    'singular_label' => __('Press'),
    	    'public' => true,
    	    'show_ui' => true, // UI in admin panel
    	    '_builtin' => false, // It's a custom post type, not built in!
    	    '_edit_link' => 'post.php?post=%d',
    	    'capability_type' => 'post',
    	    'hierarchical' => false,
    	    'rewrite' => array("slug" => "press-article"), // Permalinks format
    		'taxonomies' => array('category'),
    	    'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'outbound-links', 'revisions', 'category')
    	));

    Anything wonky about that?

    Again I really appreciate all the help you’ve provided so far 🙂

    So this issue still remains… I’m having to do a work-around using pages for each of the categories and sub categories in order to allow for pagination.

    Big bummer. Has anyone else had this issue? What’s the best way to report it to the WP development wisemen so they could take a look at it?

    Sorry i could not come back to you sooner, been busy with other things as of late.

    I can verify the issue you’re having, i see the same issue myself when trying to paginate a category archive with multiple post types set.

    However, using this method works.

    add_action( 'parse_query','changept' );
    function changept() {
    	if( is_category() && !is_admin() )
    		set_query_var( 'post_type', array( 'post', 'press_type' ) );
    	return;
    }

    Get rid of the query_posts code, leaving the regular loop(minus query_posts) and place the above code into your functions file, the paging should then behave correctly.

    NOTE: You don’t need(and shouldn’t include) these 2 lines in your post type registration code.

    '_builtin' => false, // It's a custom post type, not built in!
    	    '_edit_link' => 'post.php?post=%d',

    Mark, you’re a god among men.

    It’s working perfectly now. I did keep my query in there, though (I need to make some specific requests), and it doesn’t seem to be causing a problem.

    Thanks so much for your time and effort.

    I’d like to send you a fruit basket, but those are kind of pricey and I have one last question if you could do me this favor…

    When WP generates thumbnails automatically, it centers the image for cropping. How would I tell it to top-align crop instead?

    You da man.

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘Custom Types & Category Pagination 404’ is closed to new replies.