It is not recommended to use query_posts
. But this is not the problem, Problem is you are using PHP variable in single quotes. 'tag=$tag'
Consider these examples:
query_posts('tag=php');
//OR
query_posts("tag=$tag"); //$tag should output: php
Using WP_query //Recommended
$query = new WP_Query(array( 'tag' => 'php' ));
Related Posts:
- Related Posts loop – offset
- Get titles of all posts with current tags except current post
- taxonomy tags 404 to custom post types
- A loop with all articles with certain text strings in tags
- How to show posts with multiple tags on tag.php?
- Problem getting current post tags to show in a widget
- How to show more random posts if Tag has less than 3 posts
- Exclude page name from loop
- Display Posts Only with Specific Tag
- how to replace get_template_part(‘loop’,’tag’) with explicit styled version?
- For each loop on every word in post
- Tags on page (not post) returns nothing – why? Improved clarified question!
- Include future posts in tags and in search
- how to run loop in function.php that sends email based on specific conditions?
- Using has_tag() outside loop
- Show posts by tags excluding current post
- WordPress Tags in class
- Secondary loop cuts off at 10 posts?
- How to show only specific tag in wordpress loop
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- How to do query_posts on tags pages
- Tags outside the loop
- Retrieve each widget separately from a sidebar
- how to upload image using wp_handle_upload
- Avoiding using a loop to access a single post
- Adding ‘current_post_item’ class to current post in the loop
- Where should I use post_class()?
- Landing Page – Redirect Loop?
- How to make multiple Column in archive Page?
- Sort Popular Posts by Views for the Last Week
- Filtering posts by multiple taxonomies
- Is it possible to display previous post revision?
- Fix inefficient loop breaks post.php on form submit
- Adding shortcode closing tag after a loop
- Get Pagination (WP-PageNavi) not to work
- Filtering The Loop For Single Page and Blog Page
- the_content() seems to block my ACF-code
- Pulling current post/page data into header.php
- Removing the_content() from the page
- Loop and Page template : my WP_query don’t take args
- Change front-page layout after x amount of posts ( while in the same loop)
- Filter the loop by categories using checkbox form
- Get single post from tags array
- Duplicated posts on category page
- WordPress loop: exclude if it is the latest post
- Apply an Incremental Counter in an Array Function
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- query_posts() vs get_posts() multiple loops [duplicate]
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- How do I make a variable available inside partials?
- WordPress: Loop Help
- Unable to change the “Read more” text inside the_excerpt
- Display Post Author Link above the loop
- Enabling users to control custom loop’s query
- Conditional: IF current user has NOT commented on current post (not including post author)
- Loop counter style
- Can I add generic numbering HTML classes to items as a loop runs?
- Change post order by meta key, per post basis
- Loop Problem: Displays same set of post for all categories
- Custom Post Type on Homepage – Studiopress Genesis Framework
- New loop vs widget
- display post format text in loop
- Yoast taking over my WordPress title tag [closed]
- Pagination broken after using 2 loops to show content
- Posts not showing
- Exclude page from loop results
- How is WordPress changing the content markup?
- Use BuddyPress data in loop (mkdir)
- Wrap every four posts within a div [duplicate]
- Get most recent post for every term in a given taxonomy type
- Custom Blog Loop on Home Page
- Open Graph in Index Loop
- How to get post category and author name for cusmot API?
- How to add Default Level-0 parent and Level-1 class in WordPress Category in li element?
- Updating Post meta (ACF field) from Feed
- How to add pagination in Terms
- A code that I could not fully grasp related to foreach & count_user_posts()
- Include only one category but Exclude if is in a category from loop
- Create an archive page(loop) for edd products (music files) with an audio player?
- WordPress Pages in an Array
- the_content() keeps repeating itself
- Show different Google Map markers for different post_meta values
- numberposts not responding to wp_reset_postdata()
- My loop of random posts drags in comments of said random post
- Why my title change the last post title in my loop?
- Get child taxonomies in loop
- WordPress Multiple Loop: Home/Archives Page, with pagination
- Placing the content of one post in two side by side columns, newspaper style
- Loop not showing up on page template
- One loop for sticky, one for all the rest – how, without specifying category?
- Pass WP post content to a jQuery plugin (Fancybox)
- Query Custom Post Type by Tag
- Showposts doesn’t show the number of posts indicated
- How to end this loop properly?
- Creating mulitple loops in a sub-category page
- Can’t seem to get an else statement correct? [closed]
- Problem with ms-thumb-frame-selected class in Master Slider
- Display all posts in a page code for template
- How can you make it so the comment box shows on some pages or posts but not all?
- How to get files from loop for zip