1

I have the following code in my Functions.php file to create a custom taxonomy and post type. And I have created a series of posts within this post type and attached tags to them.

add_action( 'init', 'create_my_post_types' );

function create_my_post_types() {

register_post_type('portfolio', array(
    'label' => __('Portfolio'),
    'singular_label' => __('Portfolio'),
    'public' => false,
    'show_ui' => true,
    '_builtin' => false,
    '_edit_link' => 'post.php?post=%d',
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array('slug' => 'work', 'with_front' => false),
    'query_var' => 'portfolio',
    'supports' => array('title', 'thumbnail'),
    'menu_position' => 5
));

}

add_action( 'init', 'create_pc_db_taxonomies', 0 );

function create_pc_db_taxonomies() {
    register_taxonomy(
        'portfolio_tag',
        'portfolio',
        array(
            'hierarchical' => true,
            'label' => 'Portfolio Tags',
            'rewrite' => array('slug' => '', 'with_front' => false)
        )
    );
}

I have created a custom loop on my home page and successfully shown my posts from this type which shows they work, however when viewing the taxonomy archive I just get the message that no posts could be found... It is finding the correct template to use just not seeing posts attached to that taxonomy. Here is the code for the Taxonomy.php

<?php if (have_posts()) : ?>

        <ul id="gallery" class="portfolio-list clearfix">   

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

            <li>

                <?php if ( has_post_thumbnail() ) { ?>

                    <a class="fancybox" title="<?php the_title(); ?>" rel="bookmark" href="<?php
                    $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image') );
                    foreach ( $attachments as $attachment_id => $attachment ) {
                        echo wp_get_attachment_url( $attachment_id, 'medium' );
                    } ?>">
                        <?php the_post_thumbnail(); ?>
                    </a>

                <?php } else { ?>

                    <a class="fancybox" title="<?php the_title(); ?>" rel="bookmark" href="http://dummyimage.com/640x480/333/fff&text=x">
                        <img src="http://dummyimage.com/300x300/333/fff&text=x" alt="<?php the_title(); ?>" />
                    </a>

                <?php } ?>

            </li>

        <?php endwhile; ?>

        </ul>

        <?php else : ?>

        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>

        <?php endif; ?>

Any ideas why this is not working? Thanks

2
  • Whoever down-voted his question, be sure to leave him a comment as to what you are thinking he could have done to improve his question, please. Nov 9, 2010 at 18:56
  • It was even a full discussion that leaded Cameron to find the error in the end.
    – hakre
    Nov 9, 2010 at 19:54

2 Answers 2

4

Discovered the problem. The public parameter was set to false!

2
  • yeah that would do it. also remember that custom post types don't currently get archive pages for free. That will come in 3.1. Nov 9, 2010 at 19:38
  • That sounds silly what if someone doesn't want an archive page? I much prefer creating a page and a custom template with loop. That was one of the coolest things about Custom Post Types.
    – Cameron
    Nov 10, 2010 at 21:30
0

This also stumped me set "public" => "true" in register_taxonomy() in order for WP to access your taxonomy template.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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