I wrote code that automatically creates some posts and adds a tag to them. I can see the tags in the "All Messages" administration panel, and I can click the "Tag" link for messages to receive only those messages with tags.
However, in the plugin that I write using $ wp_query, no matter what parameters I pass, I just get a complete list of messages, regardless of whether they have the tag I'm looking for or not.
Here is 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 '<li>'; the_title(); echo '</li>'; endwhile; // Reset Post Data wp_reset_postdata();
This gives 10 results when I said this only for return 5. Actually, I should only get 2 messages back, as a total with the tag.
Looking around the Internet, it seems that many people have the same problem, but no solutions. I must have tried about 10 different ways to specify a tag, but the fact that the number of returned messages is incorrect suggests that I have something completely wrong or there is some kind of error. Wordpress version 3.4.1 if that helps.
Can any Wordpress shed some light on this?
Thanks in advance!
tags wordpress
user1647208
source share