0

I am tired to get posts using this multiple tax_query but not working at all. Can anyone fix this problem please? If anyone can fix the problem, I will grateful to him/her forever.

This query get nothing. My query is exactly look like -

$args = array(
  'posts_per_page' => 18,
  'post_type'      => 'post',
  'post_status'    => 'publish',
  'tax_query' => array (
    'relation' => 'AND',
    array (
      'taxonomy' => 'taxonomy-1',
      'terms' => array( 2024 ),
      'field' => 'term_id',
    ),
    array (
      'taxonomy' => 'taxonomy-2',
      'terms' => array( 2025, 217 ),
      'field' => 'term_id',
    ),
  ),
);

$posts = get_posts( $args );
SM FAQs
  • 11
  • 2
  • Does it work with slug instead of the term_id in the field? Maybe https://stackoverflow.com/questions/46532162/wordpress-tax-query-multiple-terms-using-or-operator solves your problem already? – Александр Фишер Dec 18 '18 at 12:18
  • 1
    Maybe use `OR` instead of `AND` else it needs both of the taxes – Stender Dec 18 '18 at 12:36
  • 1
    also, use `new wp_query()` instead of `get_posts` – Stender Dec 18 '18 at 12:36
  • Hello Stender, Thanks for your reply. I've tried all of the things you suggested but unfortunately it's working. And I don't need `OR` relation, I only need `AND` because I need to show all posts from those taxonomies together. Hope you understand. – SM FAQs Dec 19 '18 at 09:01

0 Answers0