[英]Query custom post type with custom field and order ascending by custom taxonomy
I'm trying to figure out why this won't display a list of all wines in ascending order. 我试图弄清楚为什么它不会按升序显示所有葡萄酒的列表。 From what i understand it seems this was the correct way to do it. 据我了解,这似乎是正确的方法。 It displays all the wines correctly on the page, but it doesn't order them. 它会在页面上正确显示所有葡萄酒,但不会订购它们。
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' )
);
Custom Taxonomy: categories. 自定义分类法:类别。 Custom post_type: wineinput_custom Field to order it by: wine. 自定义post_type:wineinput_custom通过以下方式订购字段:wine。
Any help would be appreciated :) 任何帮助,将不胜感激 :)
Add this function to your function.php file, 将此功能添加到您的function.php文件中,
function orderby_custom_fields( $orderby )
{
global $wpdb;
$orderby = "$wpdb->postmeta.meta_value ASC";
remove_filter( 'posts_orderby', 'orderby_custom_fields' );
return $orderby;
}
and now add this query_post data in your file, 现在将这个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);
Hope this will help you...!! 希望这个能对您有所帮助...!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.