I have a custom post type with custom fields, the one in particular is "zip". I also have an array that stores like 20 different zip codes. I want to check to see if any of those custom post types have one of those zip codes. If they do, then I want them to appear in the search results. If they don't, I don't want them to appear. How would I go about doing this..? It's driving me insane. Thanks in advance.
You will need to create two queries. The first will be one that pulls all of the custom post types in the search query.
$args = array( 'post_type' => YOUR-POST-TYPE, 'posts_per_page' => '-1', 's' => get_search_query(), ); $sort_query = new WP_Query($args); $included_results = array();
You will then have to probably print out your results so you can find where the zip code is in the array.
Run the loop, checking if the zip is in your zip code array (
in_array()) and add the id to the included results array (ex:
$included_results = $post->ID)
Next, you will want to end and reset the query, and create a new query using the same args as before, but adding
'post__in' => $included_results