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

WP_Query orderby meta key/value suddely stopped working

Some things to check. Have permissions changed during your migration? Sometimes those things change unexpectedly. Use Chrome inspector to see if any Javascript is failing to load (look for the red x). Have you updated permalinks? Is your new dedicated environment able to support the requirements of everything you’re running? If your code hasn’t changed, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)