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.

My understanding is, that custom post types can share tags with the posts also.

I have created tags and applied them to a blog post and a custom post type.

Yet when I click on a tag it only returns blog posts.

I have this line in my register post type:

'taxonomies' => array('post_tag')

But I also have this outside of the function

register_taxonomy_for_object_type('post_tag', 'projects');

Are they doing the same thing? Also why will it not return custom posts with that tag?

share|improve this question
add comment

1 Answer

Yes, both assignments do the same, but the post_tag archive is using the post type post only by default. Don’t worry, there is a hook for you: pre_get_posts.

Example with tags for pages:

// register tags for pages
add_action( 'wp_loaded', 'wpse_75297_register_tags_for_pages' );

function wpse_75297_register_tags_for_pages()
{
    register_taxonomy_for_object_type( 'post_tag', 'page' );
}

// add post type 'page' to tax query
add_filter( 'pre_get_posts', 'wpse_75297_add_pages_to_tax_query' );
function wpse_75297_add_pages_to_tax_query( $query )
{
    if ( ! is_main_query() or ! is_tag() )
        return $query;

    $query->set('post_type', array('page','post'));

    return $query;
}

Make sure the post type is spelled correctly. If your post type is project you cannot use projects in another filter.

share|improve this answer
add comment

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.