meta_query in wp_query not working as expected

It is not working because there is a custom query in the events plugin that adds the posts to be ignored (not returned) when you run WP_Query. See getHideFromUpcomingEvents() method in the-events-calendar/src/Tribe/Query.php. But there is however a filter hook that you can use there to do whatever. See the following sample code: function wpse283031_hide_ids( $ids … Read more

Wp query by 2 meta field – check if they exists / have value

Check the Codex. meta_query accepts an EXISTS comparison. $args = array( ‘post_type’ => ‘somepostype’, ‘meta_query’ => array( array( ‘key’ => ‘fname’.$userid, ‘compare’ => ‘EXISTS’, ), array( ‘key’ => ‘lname’.$userid, ‘compare’ => ‘EXISTS’, ) ) ); $query = new WP_Query( $args ); return $tempquery->found_posts; There is a note that… Note: Due to bug #23268, value is … Read more

WP_Query orderby not working on custom post_type

OK, I figured it pour reading about Orderby Parameters in WP_Query more carefully. I needed to set votes to meta_key and orderby to meta_value_num: $args = array( ‘post_type’ => ‘entry’, ‘meta_key’ => ‘votes’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 10, ‘post_status’ => ‘publish’ ); $loop = new WP_Query($args);

Can’t figure out query logic

If I follow your description right you want posts which have any $typeIDs, but all of $unionIDs ? Aside from wrong meta_query choice, you miss operator argument which specifies which kind of match you want. I think your query should be something like this: ‘tax_query’ => array( ‘relation’ => ‘AND’, // you want both conditions … Read more

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