2017-10-02 3 views
0

La requête simple, mais pour une raison quelconque, n'affiche pas les messages corrects, en essayant d'afficher un poste avec le terme mensuel , si aucun résultat affiche un message avec le terme des événements communautaires. Aucune suggestion?Wordpress: tax_query plusieurs termes à l'aide de l'opérateur OU

$todo_args = array(
    'cat' => $my_category_id, 
    'posts_per_page' => 1, 
    'tax_query' => array(
     'relation' => 'OR', 
      array(
       'taxonomy' => 'postkicker', 
       'field' => 'slug', 
       'terms' => 'monthly-to-do-list', 
       ), 
      array(
       'taxonomy' => 'postkicker', 
       'field' => 'slug', 
       'terms' => 'community-events', 
       ), 
      ), 
    'orderby' => 'date', 
    'order' => 'DESC' 
); 

Répondre

1

essayer d'ajouter tableau et faire comme ceci:

$todo_args = array(
    'cat' => $my_category_id, 
    'posts_per_page' => 1, 
    'tax_query' => array(
     'relation' => 'OR', 
      array(
       'taxonomy' => 'postkicker', 
       'field' => 'slug', 
       'terms' => array('monthly-to-do-list'), 
       ), 
      array(
       'taxonomy' => 'postkicker', 
       'field' => 'slug', 
       'terms' => array('community-events'), 
       ), 
      ), 
    'orderby' => 'date', 
    'order' => 'DESC' 
); 

Comme vous pouvez remarquer termes est pluriel et vous pouvez simplifier votre requête comme ceci:

$todo_args = array(
    'cat' => $my_category_id, 
    'posts_per_page' => 1, 
    'tax_query' => array(
      array(
       'taxonomy' => 'postkicker', 
       'field' => 'slug', 
       'terms' => array('monthly-to-do-list','community-events'), 
       ), 
      ), 
    'orderby' => 'date', 
    'order' => 'DESC' 
); 
+0

Ah intéressant , ça a marché. Merci Monsieur! –

+0

de rien;) –