How to query with get_posts() for posts with any tag

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 );

Related posts

Leave a Reply

1 comment

  1. 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 );