[英]Query custom post type with custom field and order ascending by custom taxonomy
我試圖弄清楚為什么它不會按升序顯示所有葡萄酒的列表。 據我了解,這似乎是正確的方法。 它會在頁面上正確顯示所有葡萄酒,但不會訂購它們。
query_posts(array( 'post_type' => 'wineinput_custom', 'meta_key' => 'wine', 'showposts' => -1,'tax_query' => array(
array(
'taxonomy' => 'categories',
'terms' => $subcategory3->term_id,
'field' => 'term_id',
)
),
'orderby' => 'meta_value_num',
'order' => 'ASC' )
);
自定義分類法:類別。 自定義post_type:wineinput_custom通過以下方式訂購字段:wine。
任何幫助,將不勝感激 :)
將此功能添加到您的function.php文件中,
function orderby_custom_fields( $orderby )
{
global $wpdb;
$orderby = "$wpdb->postmeta.meta_value ASC";
remove_filter( 'posts_orderby', 'orderby_custom_fields' );
return $orderby;
}
現在將這個query_post數據添加到您的文件中,
$args = array(
'post_type' => 'wineinput_custom',
'meta_key' => 'wine',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'categories',
'terms' => $subcategory3->term_id,
'field' => 'term_id'
)
),
);
add_filter( 'posts_orderby', 'orderby_custom_fields' );
query_posts($args);
希望這個能對您有所幫助...!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.