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.
Any help would be appreciated :)
Add this function to your function.php file,
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,
$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...!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.