WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to do a simple post query that will get any post that has at least one tag. This is my current code that gets the posts with tag ID 27 or 36, but I need to modify it to get all posts with at least one tag.

$args = array(
    'numberposts' => 5,
    'tag__in' => array(27,36)
$myposts = get_posts( $args );
share|improve this question
up vote 5 down vote accepted

You could try this.

$all_tags = get_tags();
$tag_id = array();
foreach( $all_tags as $tag ) {
    $tag_id[] = $tag->term_id;

$args = array(
    'numberposts' => 5,
    'tag__in' => $tag_id
$myposts = get_posts( $args );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.