Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I found this question asked elsewhere, but it was unanswered, so I'm asking myself.

I have a custom post type (Features) that shares my Categories and Tags with my standard posts. I'm listing my categories with this:

<?php wp_list_categories('title_li=&hierarchical=false'); ?>

The resulting list includes categories that are applied only to Features. I know this is working because some of these point to empty pages. So the problem is with the loop that I'm using on my archive page.

Here's the loop:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>   

    <?php $custom_classes = get_post_meta($post->ID, 'custom_post_class', false);  ?>
    <article <?php post_class($custom_classes) ?> id="post-<?php the_ID(); ?>" role="article">
        <header>
            <hgroup>
                <h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
                <h2 class="vcard">By <?php the_author_posts_link() ?></h2>
                <h3><time datetime="<?php echo get_the_date('c'); ?>"><?php echo get_the_date('F jS, Y'); ?></time></h3>
            </hgroup>
        </header>
        <section class="text clearfix">
            <?php the_content(); ?>
            <?php edit_post_link('Edit this post ✍', '<p>', '</p>'); ?>
        </section>
    </article>

<?php endwhile; ?>

Can you tell me what I'd need to add in order to get my custom post type to show up here?

share|improve this question

2 Answers 2

I found this answer on the WordPress forum to be of help:

http://wordpress.org/support/topic/custom-post-type-posts-not-displayed?replies=5#post-2805344

basically, the poster references a post by Justin Tadlock (who is pretty much an authority in WordPress theme and plugin desing by the way. Follow his blog if you want to get savvy on WordPress.)

http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page

In his blog post he provides a code snippet that you can add to your functions.php page:

add_filter( 'pre_get_posts', 'my_get_posts' );

function my_get_posts( $query ) {

    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote' ) );

    return $query;
}

and this seems to work fairly well. Of course, you might want to change is_home() to is_archive() and substitute album, movie, quote for your custom post type handles as you've registered them with the register_post_type function.

share|improve this answer

First, check if this is set in your code for registering the CPT: 'has_archive' => true.

Next, do you have an archive page for the custom post? Although it is not mandatory that you should have an archive page for the CPT, as the main index will be used as a fallback, I think making a CPT archive file should solve your problem. Copy this code to a new php file and name it as archive-feature.php (where 'feature' is your custom post type, please check if the name and case is right). Also you might need a singular template for your CPT single post. That file should be named as single-feature.php. For more on template files: Template Hieracrhy for CPTs. Hope this helps!

share|improve this answer
    
I do have an archive for my custom post type, and it works as expected. I'm hoping to click that category list and have it take me to an archive that displays posts and features together, in the same list. Is this possible? –  Thrillho Nov 17 '11 at 1:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.