wordpress - Sort wp_query by meta value -


i have custom post type namely portfolio, need able sort meta value authors name ::: i've bee trying several examples none work ::: appreciated :::

my code

$args = array(     "post_type" => "portfolio",     "meta_key" => "authors_name",     "orderby" => "meta_value",     "order" => "asc" );  $custom_query = new wp_query( $args ); 

this not work

$args = array(     "post_type" => "portfolio",     "meta_key" => "authors_name",         'meta_query' => array(             array(                 'key' => 'authors_name',             ),             ),             'orderby' => 'meta_value',             'order' => 'asc', ); 

i able sort issue add_filter('pre_get_posts' ::: in essence script looks :::

function laudes_order( $wp_query ) {          $wp_query->set('meta_key', 'authors_name');         $wp_query->set('orderby', 'meta_value');         $wp_query->set('order', 'desc');  }  add_filter('pre_get_posts', 'laudes_order');   $args = array(     "post_type" => "portfolio", );   $custom_query = new wp_query( $args ); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -