Fastest way to do meta query when I don’t need the actual posts, and just need post_id?
Fastest way to do meta query when I don’t need the actual posts, and just need post_id?
Fastest way to do meta query when I don’t need the actual posts, and just need post_id?
I ended up finding two solutions within WordPress’ capabilities. Storing available rather than unavailable dates The first solution would be to have the agency select all available dates rather than selecting unavailable dates. Our example listing would then have a custom field listing_available: update_post_meta($post_id, “listing_available”, “/20140101/20140102/20140103/20140104/”); I would then be able to run the following … Read more
This might require writing custom sql with a subquery: $results = $wpdb->get_results(” SELECT * FROM $wpdb->posts WHERE ID NOT IN ( SELECT post_id FROM $wpdb->postmeta WHERE meta_key = ‘my_custom_field’ and meta_value = 2 ) “); then just iterate through the results as described here.
I don’t think you need the relation parameter. It defaults to AND. $nowtime = time(); $the_query = new WP_Query( array( ‘post_type’ => ‘promos’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘wpcf-type-of-promo’, ‘value’ => ‘walls’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘wpcf-date-and-time-start’, ‘value’ => $nowtime, ‘compare’ => ‘<‘, ‘type’ … Read more
The parameter ‘meta_query’ is an array, so you can add multiple meta keys. In the doc, below the section “Example: Multiple Meta Entries – Multi dimensional array”, you can find an example where the relation is set to ‘OR’: $query_args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘foo_key’, // ‘value’ => … Read more
You could use the ‘posts_orderby’ filter: function custom_loops($query) { if ( is_post_type_archive(‘my_post_type’) ){ $query->set( ‘posts_per_page’, 40); $query->set( ‘meta_key’, ‘custom_meta_sponsored’); $query->set( ‘orderby’, ‘custom_meta_sponsored’); $query->set( ‘order’, ‘DESC’); add_filter( ‘posts_orderby’, function ( $orderby, $query ) { if ( $query->get( ‘orderby’ ) != ‘custom_meta_sponsored’ ) return $orderby; global $wpdb; $orderby = $wpdb->prepare( ‘CASE WHEN ‘ . $wpdb->postmeta . ‘.meta_value … Read more
Shouldn’t it be like this (doc)? $meta_query[] = array( ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘estate_property_google_maps’, ‘value’ => $al[‘0’], ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘estate_property_google_maps’, ‘value’ => $al[‘1’], ‘compare’ => ‘LIKE’ ), ) );
The reason you’re only getting those users that have that meta_key is because you’re include ‘meta_key’ => ‘…’ in $args. That limits results to those that have that key, regardless of any clauses you may have in a meta_query. This applies to WP_Query, WP_User_Query and WP_Comment_Query. Starting in WP 4.2, you can “name” the clauses … Read more
What you are doing is not a valid way of retrieving and checking serialize data from the WP. You may insert array as a user meta but this array behind the scenes is transformed to serialize string something the MySql can handle. There are options for searching with the LIKE operator but I don’t endorse … Read more
get_posts() is a rather generic wrapper for retrieving set of posts and just that. As such it purposely unmakes some of the arguments typical for loops. Specifically it ignore stickies: $r[‘ignore_sticky_posts’] = true; So if you want more loop-like behavior you should be using instance of WP_Query object instead.