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
Discovered the problem. The
public
parameter was set tofalse
!This also stumped me set “public” => “true” in register_taxonomy() in order for WP to access your taxonomy template.