Sort posts by custom field value
-
Hi there,
I’m using wck custom fields called “DoctorsName” to store names in my site and in it, there are metabox fields for “First names” and “last name”.
I wanted to sort the names by last name using wordpress meta queries but since wck custom fields is an array and meta_key doesn’t accept an array, I can’t find a way to make it work.
my code is this:
<?php $q=array( 'post_type' => 'doctors', 'order' => 'ASC', 'meta_key' => 'DoctorsName', 'orderby'=> 'meta_value', 'posts_per_page' => '10', ); $my_query = new WP_Query($q); if( $my_query->have_posts() ) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
I was hoping that ‘meta_key’ =>’DoctorsName[“last-name”]’ would work but got no luck.
I would really appreciate if someone can help me out.
thanks,
https://www.ads-software.com/plugins/wck-custom-fields-and-custom-post-types-creator/
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Sort posts by custom field value’ is closed to new replies.