Help ordering Post loop by two meta values

If you’re using WordPress 4.2 or newer then you can do the following: $args = array( ‘post_type’ => ‘events’, ‘posts_per_page’ => 10, ‘meta_query’ => array( ‘relation’ => ‘AND’, ‘start_date_clause’ => array( ‘key’ => ‘start_date’, ‘compare’ => ‘EXISTS’, ), ‘ticket_status_order_clause’ => array( ‘key’ => ‘ticket_status_order’, ‘compare’ => ‘EXISTS’, ), ), ‘order_by’ => array( ‘start_date_clause’ => ‘ASC’, … Read more

Combining categories (Query posts with multiple taxonomy terms)

This type of behavior is documented in the WP_Query documentation. You can use a comma-separated list of category IDs instead of just one. For example (ripped right off the Codex page): $query = new WP_Query( array( ‘cat’ => ‘2,6,17,38’ ) ); With tags it’s a little different, but not too much so: $query = new … Read more

querying data via $wpdb and get_row

Try this. $query = “SELECT * FROM wp_cf7dbplugin_submits a,wp_cf7dbplugin_submits b WHERE a.field_name=”Buyer” AND a.field_value = 1 AND a.submit_time = b.submit_time AND b.field_name = carbrand AND b.field_value=”Mercedes””; global $wpdb; // return the number of rows found $results = $wpdb->num_rows($query); var_dump($results);

Search: how to extend the existing search to include a custom table

By default, WordPress searches by keyword. What this means is that when passed the search query “Loren Ipsum”, WordPress builds the following for the WHERE clause: ((wp_posts.post_title LIKE ‘%Loren%’) OR (wp_posts.post_content LIKE ‘%Loren%’)) AND ((wp_posts.post_title LIKE ‘%Ipsum%’) OR (wp_posts.post_content LIKE ‘%Ipsum%’)) This answer can be helpful to you ! There is also a plugin for … Read more