• Hello everybody,

    I’m building a theme for my personal website and made a custom taxonomy for photos.
    I’m trying to extract posts from that taxonomy, with an “OR” relation. Later on I use get_posts($args)

    $args = array(
            'post_type' => 'attachment',
            'post_mime_type' =>'image',
            'posts_per_page' => -1,
            'tax_query' => array(
                'relation' => $a['rel'], // Here's the problem
                $tq
            ),
            'orderby' => $orderby,
            'order' => $order
        );

    This is the arguments array. $tq is an array of arrays containing each term I’m trying to relate with an “or”.
    It works until I try to use 'relation' => 'OR'

    Any help will be very appreciated.

    Thanks in advance

Viewing 1 replies (of 1 total)
  • Thread Starter kvl

    (@kvl)

    I ended up merging the resulting arrays of posts, extracting IDs from those posts into an array, then cleaning them using array_unique($arr); and finally querying again using post__in.
    It’s not clean nor stylish but it works well.
    Any suggestion on cleaning up the code?

Viewing 1 replies (of 1 total)

The topic ‘tax_query "OR" relation -> no posts are extracted’ is closed to new replies.