$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - why category__and and category__in wont work togather?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - why category__and and category__in wont work togather?

matteradmin8PV0评论

I am having an issue here. I want to get all the post that are related to the current post at the same time it will also have a common category term.

for example:

Post XYZ has categories car, Truck, and Bus.

So i want to get any posts that have car or truck or bus at the same time it will also have category "Toronto"

What would be the query?

I am having an issue here. I want to get all the post that are related to the current post at the same time it will also have a common category term.

for example:

Post XYZ has categories car, Truck, and Bus.

So i want to get any posts that have car or truck or bus at the same time it will also have category "Toronto"

What would be the query?

Share Improve this question edited Feb 8, 2019 at 23:57 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Jan 12, 2014 at 0:32 Tpn KnvlTpn Knvl 32 bronze badges 2
  • 1 have a look at tax_query for complex taxonomy queries. – Milo Commented Jan 12, 2014 at 0:34
  • @Milo Perfect Solution. – Tpn Knvl Commented Jan 12, 2014 at 0:50
Add a comment  | 

1 Answer 1

Reset to default 1

You need a query like this -

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => array( 'car', 'truck', 'bus' ),
            'operator' => 'IN'
        ),
        array(
            'taxonomy' => 'category',
            'field' => 'name',
            'terms' => 'Toronto'
        )
    )
);
Post a comment

comment list (0)

  1. No comments so far