[英]WP_Query category parameter is not working
我正在創建具有屬性和所有屬性的短代碼,但event_category除外。 當我添加“ event_category”屬性時,按照添加的類別它沒有給出結果。
這是我的簡碼屬性
// Shortcode Default Array
$default_shortcode_attrs = array(
'type' => 'upcoming',
'search' => 'true',
'event_category' => '',
'events_limit' => '-1',
);
extract(shortcode_atts($default_shortcode_attrs, $attr));
以下是查詢參數
$args = array(
'posts_per_page' => -1,
'post_type' => 'event_listing',
'post_status' => 'publish',
'event_listing_category'=> $event_category,
);
$query = new WP_Query($args);
“ event_listing_category”是自定義分類法的名稱。 請指導我為什么該查詢不按事件類別提取事件。
任何幫助將不勝感激。
謝謝
改用tax_query如下:我假設您在$ event_category中只提供了一個類別標簽。 如果該變量中有多個類別標簽,則嘗試將其轉換為數組,然后將整個數組($ event_category)替換為數組。
$args = array(
'posts_per_page' => -1,
'post_type' => 'event_listing',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'event_listing_category',
'field' => 'slug',
'terms' => array( $event_category)
)
)
);
$query = new WP_Query($args);
有關如何在查詢中查詢自定義分類法的信息,請參閱http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters 。
WP_Query函數無法將'event_listing_category'
理解為參數,您必須告訴wordpress這是您想要的自定義分類法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.