Rumah > Soal Jawab > teks badan
Saya cuba menggunakan WP_Query untuk membuat pertanyaan yang mengandungi elemen meta_query dan elemen tax_query. Lebih kritikal, saya tidak mahu mencari hasil yang memenuhi kedua-dua syarat (dan klausa DAN), saya ingin mencari hasil yang memenuhi satu atau satu lagi daripadanya (OR klausa).
$loop = new WP_Query( array( 'post_type' => 'tickets', 'paged' => $paged, 'order' => $order, 'orderby' => $orderby, 'meta_query' => array( array( 'key' => 'tps_email', // Use 'key' for author 'value' => 'web@data.com', // Replace with the author ID you want to query 'compare' => 'LIKE', // Use '=' to match the author ID ), ), 'tax_query' => array( array( 'taxonomy' => 'topic', // Replace with your custom taxonomy name 'field' => 'slug', // You can use 'id', 'slug', or 'name' depending on how you want to identify the term 'terms' => 'housekeeping', // Replace with the slug of the specific term you want to query ), ), ) );
Saya menerima output ini
P粉0990000442024-04-05 00:33:11
Begini cara untuk menyediakan hubungan "ATAU" antara meta_query dan tax_query:
$args = array( 'post_type' => 'tickets', 'paged' => $paged, 'order' => $order, 'tax_query' => array( 'relation' => 'OR', // Set the relationship to OR array( 'taxonomy' => 'topic', 'field' => 'slug', 'terms' => 'housekeeping', ), array( 'taxonomy' => 'your_taxonomy_2', 'field' => 'slug', 'terms' => 'term_slug_2', ), ), 'meta_query' => array( 'relation' => 'OR', // Set the relationship to OR array( 'key' => 'tps_email', 'value' => 'web@data.com', 'compare' => '=' ), array( 'key' => 'custom_field_2', 'value' => 'custom_value_2', 'compare' => '=' ), ), );