0
$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.

1 Answer 1

1

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),
        ),
    ),
);
1
  • 1
    hahaha Actually, it does work i just forgot to clear server caching and term transients. Sorry about that. When i add your array, it doesn't work! hahaha, but i'll still give you the votes May 25, 2022 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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