Orderby meta_key/meta_value not displaying anything, am I overlooking anything?
I have an issue with my orderby
using get_posts()
. I want to order in alphabetical order a list by city name using a custom meta field, but it comes back empty. However when I orderby title, the list is displayed with no issues.
I activated WP_DEBUG
and no errors or notices were found.
I checked the query in hopes that I was using the wrong meta_key
, but everything looks as it should be. Am I missing anything?
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_postmeta.meta_key = 'ville' ) AND ((wp_posts.post_type = 'ecole' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private'))) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC
$posts = get_posts( array(
'post_type' = 'ecole',
'posts_per_page' = -1,
'meta_key' = 'ville',
'orderby' = 'meta_value',
'order' = 'ASC'
) );
if ( $posts ) {
foreach ( $posts as $post ):
List goes here
?php
endforeach;
}
Topic meta-value get-posts custom-field custom-post-types Wordpress
Category Web