WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type Taxonomy Issue (3 posts)

  1. Jesse Friedman
    Member
    Posted 2 years ago #

    I declared a custom post type. I can add new, save and display my cpt and it's meta data. This all works nicely.

    When declaring my cpt I set
    'taxonomies' => array('category'),

    I then added some categories manually and assigned specific cpt posts to those categories.

    The categories in this example are all 50 states.

    When I go to http://domain.com/category/rhode-island/ I only get results for regular posts that are in the category, however all cpt's have been excluded.

    These results are built by the template page archive.php

    All attempts to do archive-cpt-name.php have failed but I am not concerned with this at the moment.

    If I perform a search within the category my cpt's show so for example http://domain.com/category/rhode-island/?s=a will show all posts and cpt's with the letter "a".

    I have been able to search more specifically and pull up just cpt results as well.

    The search results are powered by the search.php template which is an exact duplicate of the archive.php.

    My main question here is what would keep the custom post type posts from showing in archive/category results but allow them to be searched with in that category?

  2. aware
    Member
    Posted 2 years ago #

    I don't think custom post types are shown by default. I think you have to define them before your query

    Something like.

    <?php query_posts( array('post_type', => 'your-post-type') ); ?> before your loop

  3. aware
    Member
    Posted 2 years ago #

    also keep in mind that you can do multiple post types

    <?php query_posts( array(
    	'post_type' => array('post',
    			'your-post-type-1',
    			'your-post-type-2',
    			'your-post-type-3'
    	) )
    ); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic