• Hello,

    I hate to bring this up because there are already so many topics covering this. I know because I have read about 50 of them but I cannot find a resolution. So I am hoping a fresh topic may help.

    I have created a custom post type and everything is working great except one small thing: the posts that are created within the custom post type are not showing in the archive list or in the category list it is assigned to.

    The odd thing is that the number of posts will show by the category name in the sidebar but when you click on the category, no posts will show.

    I did create a single-custompostype.php file and it works fine.

    I tried switching to the Twenty Twelve theme and added my custom post type and even that does not work.

    There are no plugins activated.

    I have has_archive => true with the custom post type as well as the other required settings.

    I have tried flush_rewwrite, as well as some other pagination tricks but nothing is working.

    I have re-saved the permalinks settings numerous times to no avail.

    So… I am at my wits end.

    Any help would be appreciated.

    Thanks much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter hixsonb

    (@hixsonb)

    Just as a quick update, I can add the following code to the archive.php and/or category.php and it WILL return results of the custom post type.

    <?php query_posts(array(‘post_type’ => array(‘post’, ‘services’))); ?>

    (services is the name of the custom post type)

    HOWEVER, it still doesn’t seem to be working right with because if I create a archive-services.php or category-services.php, it isn’t recognized.

    So, still looking for help.

    Thank you.

    Thread Starter hixsonb

    (@hixsonb)

    Getting Closer.

    Adding this code to my functions.php enabled the ability for the custom post types to show in categories and archives.

    However, the archive-services.php and categoreis-services.php still don’t work.

    (services is the name of my custom post type).

    <?php add_filter(‘pre_get_posts’, ‘query_post_type’);
    function query_post_type($query) {
    if(is_category() || is_tag()) {
    $post_type = get_query_var(‘post_type’);
    if($post_type)
    $post_type = $post_type;
    else
    $post_type = array(‘post’,’services’,’nav_menu_item’); // replace cpt to your custom post type
    $query->set(‘post_type’,$post_type);
    return $query;
    }
    } ?>

    (I had to add the line ,’nav_menu_item’ because when I first added the code, my nav menu went away.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Type not in archives or categories.’ is closed to new replies.