WordPress.org

Forums

Custom Post Type UI
[resolved] Want CPT with related tags to show (8 posts)

  1. jeffreyd000
    Member
    Posted 1 year ago #

    How do I get my CPT entries with the same Tag that is selected in related Posts to show up along with the Posts entries when viewing by tags like this? http://mydomain.com/tag/mytag/

    I can select the tags in the backend and I they are being displayed in a custom template using get_the_tag_list();

    But when I click the tag I only see items from the Posts area.

    Thanks,
    Jeffrey

    https://wordpress.org/plugins/custom-post-type-ui/

  2. Michael Beckwith
    Member
    Plugin Author

    Posted 1 year ago #

    I wager that the custom post type isn't part of the query being made for the tag archive. I'd check out the following link to see how to add the post type to the query http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

  3. jeffreyd000
    Member
    Posted 1 year ago #

    Nope, it shows find in search results. just not when viewing posts by Tag.

  4. Michael Beckwith
    Member
    Plugin Author

    Posted 1 year ago #

    which is still related to what I said. The tag archive is just querying for the "post" post type, you need to make it query for the CPT you created as well.

  5. jeffreyd000
    Member
    Posted 1 year ago #

    Thank you for your guidance. Your premise was correct but the code in the codex did not work.

    I solved it with this...

    function add_custom_types_to_tax( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    // Get all your post types
    $post_types = get_post_types();
    
    $query->set( 'post_type', $post_types );
    return $query;
    }
    }
    add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );

    Found here - http://premium.wpmudev.org/blog/add-custom-post-types-to-tags-and-categories-in-wordpress/

  6. Michael Beckwith
    Member
    Plugin Author

    Posted 1 year ago #

    Whatever works, I say. Technically I don't think you even need to do the return $query part, but that's mostly if you want a bit more tidy of code.

    Glad you got it figured out :)

  7. jeffreyd000
    Member
    Posted 1 year ago #

    Thanks again, happy to support a great plugin. I have donated in the past for your efforts!

  8. jeffreyd000
    Member
    Posted 1 year ago #

    @Michael Beckwith Made another donation, thanks again. Your work and time is appreciated.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Post Type UI
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic