Count posts per taxonomy else change taxonomy if less than x number

$taxonomy = $tag-count  3 ? 'post_tag' : 'category';

$cats_or_tags = $tag-count  3 ? $tag_ids : $cat_ids;

$args = array(
    'tax_query' = array(
     array(
    'taxonomy'     = $taxonomy,
    'field'        = 'id',
    'terms'        = $cats_or_tags

The first part of this ternary works when checking the count of posts in a specific tag but the 2nd part doesn't.

It's supposed to set the taxonomy and terms values if there's more than 3 posts tagged otherwise when less than 4, display posts from categories instead of tags.

Topic terms wp-query Wordpress

Category Web


I'm guessing you are using a tax_query here.

If you try to query multiple categories or taxonomies, the terms field expects an array

$args = array(
    // other query arguments
    'tax_query' => array(
        array(
            'taxonomy' => $taxonomy,
            'field'    => 'id',
            'terms'    => array($cats_or_tags),
        ),
    ),
);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.