• In our custom function file we have several functions of the type:

    function author_post_type( $query ) {
    if ( is_category( array( 2, 5, 8, 14 ) ) && $query->is_main_query() ) {
       $query->set( 'post_type', array( 'author_bio' ) );
       $query->set( 'orderby', 'meta_value');
       $query->set( 'meta_key', 'author_last_name' );
       $query->set( 'order', 'ASC' );
    }
    }

    After working successfully for a year and a half, these functions suddenly stopped working. Apparently the set-post-type line is failing, because the page produces no results. (No results because all posts in the selected category are author post types, in this example, and without setting the post type, those are not found.)

    Oddly enough, a similar function with an if-statement testing for taxonomy —
    if ( is_tax( 'genre' ) && $query->is_main_query() ) {
    — continues to work fine.

    So “is_tax” continues to work, but “is_category” no longer works.

    We recently updated to WordPress 3.8. Any advice?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m having the exact same issue, I believe the is_category() function call is causing is_main_query() to return nothing, and vice versa in 3.8. Here’s my post.

    Edit: I found a temporary solution. Change the

    is_category()

    to

    $query->query['category_name'] == 'the-category-slug'

    Replacing “the-category-slug” with the actual slug.

    Thread Starter bvcgroup

    (@bvcgroup)

    Thanks for letting me know. At least it’s not just me. I’m hoping the WordPress folk will take a look at this? The alternative right now is to rebuild the broken pages to use taxonomies, or to create a custom page-template for each broken page, and make the query there. The latter works — I’ve already done it for one page — but it results in redundant code.

    I would just do something like this in the mean time:

    $categories = array(
    	'category-slug',
    	'category-slug-2',
    	'category-slug-3',
    	'category-slug-4',
    	'category-slug-5'
    );
    
    if ($query->is_main_query() && in_array($query->query['category_name'], $categories)) {
    	// modify query here
    }

    Same thing, but a little more verbose.

    Thread Starter bvcgroup

    (@bvcgroup)

    Thank you! That work-around let me get the important pages back up with minimal effort. I really appreciate it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem with displaying custom post types after upgrade to 3.8’ is closed to new replies.