Contents
Here’s my code: // Now retrieve all items matching this brand name . . . $query=new WP_Query(array(‘posts_per_page=5’, array(‘tag’ => array($brand_name)))); // The Loop while ( $query->have_posts() ) : $query->the_post(); echo ‘
‘; endwhile; // Reset Post Data wp_reset_postdata();
How do I find the current tag name in WordPress?
1 Answer. You can get the slug by getting the queried object while on the tag page, like so: php $tag = get_queried_object(); echo $tag->slug ?>
How does WP _ query work with categories and tags?
Note that this uses an array not a string, so you code it differently. The parameter has two underscores in its name: use just one and it won’t work. The next parameter looks for posts in one or more of an array of categories. It actually works in the same way as the cat parameter, and also takes the category ID as its value.
How to get the list of tags in WordPress?
(string) (Optional) String to use before the tags. (string) (Optional) String to use between the tags. (string) (Optional) String to use after the tags. (int) (Optional) Post ID. Defaults to the current post ID. (string|false| WP_Error) A list of tags on success, false if there are no terms, WP_Error on failure.
How does query all posts with specific tag work?
My query works if I publish a post with the tag that I need and list all the posts with that tag, but when I publish a post with another tag, it’s fetching the newly published post. It’s a lot easier to create a new WP_Query than it is to try clearing or overwriting the original.
How to fire WP _ query for tag for custom post?
Instead of using tag= in your wp_query use post_tag= this will surely solve your problem. Don’t use Query period. Both query_posts and wp_query effect global variables. Use get_posts instead, then you don’t have to worry about your queries impacting other parts of the application/theme.