• I’ve created a custom post type called Tutorials and I need to be able to show a list of tags that each tutorial post may be associated with. I’ve had no problem querying by a certain known tag, with this:

    $loop = new WP_Query( array(
      'post_type' => 'tutorial',
      'tag' => 'tagtest',
      'posts_per_page' => -1
      )
    );

    This works with a hard-coded value as in the example above, but how do I create a list of tags (and eventually categories as well) that will take people to all tutorials with that tag. Right now, it takes me to all regular posts associated with that tag and none of the tutorials are listed. The url is localhost/testsite/tag/tagtest and I want to see something more like localhost/testsite/tutorials/tagtest. I’ve been playing around with this and maybe I’m missing something simple.

    I should mention that I know how to list the tags with this:

    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        echo '<a href="http://localhost/testsite/tutorial/tag/'.$tag->name.'">' . $tag->name . '</a>';
      }
    }

    But how do I load a page that knows what tag to set in my loop?

    Also my loop code above was in a page template, but using a template page means I don’t get the url I’d like to see.

    Any help would be greatly appreciated. Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    May be I can help do you want to know

    Right now, it takes me to all regular posts associated with that tag and none of the tutorials are listed

    The url is localhost/testsite/tag/tagtest and I want to see something more like localhost/testsite/tutorials/tagtest

    If Tag is a default taxonomy you can use permalink in Settings.

    Thread Starter rtc35

    (@rtc35)

    Thanks Arvind. If I understand you correctly, you’re saying to set tutorials as my tag base? That’s an interesting idea and may solve part of my problem, but if I want to continue using tags for normal, non-tutorial based tag related queries, they’ll all list under tutorials.

    Plus, changing the tag base doesn’t help me query for tutorial post types. I still get only normal posts when clicking a tag.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Types Dynamically Queried by Tags or Categories’ is closed to new replies.