Custom Post Types Dynamically Queried by Tags or Categories
-
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
- The topic ‘Custom Post Types Dynamically Queried by Tags or Categories’ is closed to new replies.