order by meta_key [duplicate]

Format of this meta is OK – it should work. I’m not sure what you’re doing in this query args, though. You use meta query incorrectly. If you do it like this, it should work fine: $my_query = new WP_Query( array( ‘author’ => $current_user->ID, ‘post_type’ => ‘tribe_events’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘meta_key’ => … Read more

Sorting not working with get_posts

Hello bro try this will work ! $newsItems2 = get_posts( [ “post_type” => “post”, “post_status” => “publish”, “posts_per_page” => 3, “orderby” => “date”, “order” => “DESC”, “meta_key” => “news__type”, “meta_value” => “general”, ] );

meta_query and strange orderby behaviour

You could try $args = array( ‘post_type’=> ‘events’, ‘meta_query’ => array( array( ‘key’ => ‘_startdate’, ‘value’ => $today, ‘compare’ => ‘>=’, ‘type’ => ‘DATE’, ), array( ‘key’ => ‘_enddate’, ‘value’ => $today, ‘compare’ => ‘>=’, ‘type’ => ‘DATE’, ), ‘relation’ => ‘OR’, ), ); function jumpin_thru_hoops( $a ) { global $wpdb; $a = $wpdb->postmeta.’.meta_value+0 ASC’; … Read more

How to output meta_key in wp_postmeta?

If you want to get post meta, then you just need to call get_post_meta() function and pass three arguments: current post id, your meta key and true value (what indicates that you want to receive only one value in return). Simply call echo get_post_meta( get_the_ID(), ‘_su_description’, true ); in your template and your meta value … Read more

Sort posts by post views and consider meta key

The SQL looks correct. (You can substitute new WP_Query for get_posts and echo $my_posts->requests to see it.) So I am going to guess that the sticky posts are making it look as though the sorting doesn’t work. Add ‘ignore_sticky_posts’ => true to your arguments.

Get foreach for meta_query value

Don’t implode $artistNames. The value meta_query argument will take an array if you use any of several compare arguments. You need IN, I believe. value (string|array) – Custom field value. It can be an array only when compare is ‘IN’, ‘NOT IN’, ‘BETWEEN’, or ‘NOT BETWEEN’…. http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters Assuming that $artistNames is an array of ids … Read more

Multiple Queries with meta_query

You could try this which is mostly code clean up but may solve your problem. I removed the relation from meta_query as it’s only needed if you have multiple meta keys in your query, which you don’t. I’ve also replaced the rewind_posts() with wp_reset_postdata() and finally, you were ending your IF statements earlier than your … Read more