When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?

This question is a follow up to a question I recently asked. I’ve implemented what seemed to be the only solution, and it seems to work (YAY!). I just need to verify that: This is really the only way to modify the query to match with a match to the (post_title OR post_content OR any … Read more

How do I create my own nested meta_query using posts_where / posts_join?

Some of my posts (not all) have a price as a meta key/value. Today I use the pre_get_posts action so that my users can search for prices that are between a certain value. This is the code that I’m using today, and it’s working. add_action(‘pre_get_posts’, ‘my_search_price’); function my_search_price( $query ) { if ($query->get(‘maxprice’) != “” … Read more

Extending WP_Query — Optimise SQL query

I’m storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class WP_Query_Posts_User_Follows extends WP_Query { function __construct($args=array()) { if ( !empty($args[‘followed_by’]) ) { $this->followed_by = $args[‘followed_by’]; add_filter(‘posts_where’, array($this, ‘posts_where’)); } parent::query($args); } function … Read more

Custom query incorrectly returning everything [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years … Read more

Search ONLY by meta key / meta values

I’m almost there on this one. On functions.php i have this: function base_home_product_post_type( $query ) { if($query->is_search() && $_POST[‘box’] == ‘sku’) { $query->query_vars[‘post_type’] = ‘product’; $query->query_vars[‘meta_key’] = ‘sku’; $query->query_vars[‘meta_value’] = $query->query_vars[‘s’]; return; } } add_action(‘pre_get_posts’, ‘base_home_product_post_type’, 1); And it does what it’s told. Searches for the search string on the meta_key ‘sku’. Problem here is … Read more

Is there any difference between hooks posts_where with posts_join and posts_search performance wise?

I want to know which filter hook I should use that performs faster. I did try both several times and I noticed that posts_search is a bit faster than using the combination of posts_where and posts_join What is your take on this? 1 Answer 1 All of these hooks are called in a similar fashion … Read more

Prevent pre_get_posts filter on specific post type

I am running into one issue with pre_get_post filter. Actually I have 4 post types. Post, Pages, Events, and Venue. I created one custom field called city for event and venue post type. When creating custom field I have one option to select post type on which I want to display that custom field. Now, … Read more