i have a custom search widget, that is searching only one custom post type that contain a meta_key that is greater than or equal to 1, in which i am gathering post_id. of all of those post_id(s), i am wanting to exclude those that have meta_key '_start_date' (stored like 01-16-2015) with value >= 'search_input_start_date' AND meta_key '_end_date' (stored like 01-16-2015) with value <= 'search_input_end_date'.

my question is: should I be using the action 'pre_get_posts' and the above as $args, or should I be using the filter 'posts_where' and directly going to the $wpdb ?

  • I always use the posts_where filter for such things.
    – shanebp
    Commented Jan 17, 2015 at 0:48

1 Answer 1


In general this would make sense at pre_get_posts since you could just express conditions as meta query and let WP figure out SQL.

In your specific case this won't work, since that format is horrible for programmatic comparison. Unless you can change format to something more friendly, you will probably have to write some pretty custom SQL to make it work.

  • ok. Thank you @rarst, do you think then it would be a good idea to run the $where clause, OR instead of the $where (using custom SQL), use something out of the $where['pieces'] for returning the $query perhaps?
    – Ray Flores
    Commented Jan 20, 2015 at 16:40
  • i think i have it now... i marked as answered, thanks again @rarst!
    – Ray Flores
    Commented Jan 21, 2015 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.