Support » Fixing WordPress » How to loop tags in custom post type

  • Resolved modeman


    i have using custom post type named “katalogas” and i want to show all posts by choosen tags in tag.php file, now i have code that shows absolutely all posts from all categories.

    How to show only posts with selected tag?

    My code:

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer



    You can use this way of querying on a tag template file (tag.php):

    $current_tag = get_query_var('tag');
    	'tag' => $current_tag,
            'post_type' => 'katalogas'

    But a better way would be without a query_post on your tag template file (tag.php) and with this in your theme’s functions.php:

    function my_post_queries( $query ) {
      // not an admin page and is the main query
      if (!is_admin() && $query->is_main_query()){
        // only use the post_type katalogas on tag pages
          $query->set('post_type', array('katalogas'));
    add_action( 'pre_get_posts', 'my_post_queries' );
    Querying Posts Without query_posts

    Thanks, works perfect!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to loop tags in custom post type’ is closed to new replies.