0

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 ?

1
  • I always use the posts_where filter for such things. – shanebp Jan 17 '15 at 0:48
0

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.

2
  • 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 Jan 20 '15 at 16:40
  • i think i have it now... i marked as answered, thanks again @rarst! – Ray Flores Jan 21 '15 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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