2

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?

1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy