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
Related Posts:
- filter search result with custom post type meta key
- How Do I Use WP_Query to Run This Database Query as Search Result?
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Custom search for custom post meta with pre_get_posts interferes with WP search
- Custom post type search using $_SESSION and pre_get_posts
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- Custom Post Search
- pre_get_posts not firing at all
- Search for portfolio tags & mixing portfoliotags and post tags
- What content types are shown at a search page?
- Can NOT search my custom post type?
- Search one custom post type ONLY, disable “all posts”
- Custom post_type search pages
- Query multiple taxonomies with pre get posts
- Main menu not appearing in custom post type archive
- Pagination Error : Duplicate argument being outputted
- WordPress search and date filter not working with custom post type
- Custom Empty Results page for my Custom Post Type
- Excluding a Custom Post Type with a specific tag using pre_get_posts
- Custom filter for main search: how to exclude specific post_type from search results
- Add custom attributes to a post
- Display an icon based on post type
- how to show records that don’t have custom meta value
- how to get this tax_query working?
- Select2 AJAX and WP Query Returns ALL and does not filter
- Custom Taxonomy Search result page
- CPT is simply not displayed in the main archive with “pre_get_posts”
- How to group search results by post type and only if post type result is not empty?
- find custom post type post by searching its custom field with my string
- search custom post type by custom fields on front end
- Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
- Custom Search | check multiple meta_value for search value
- Hide custom post type from search based on custom taxonomy
- How to query for posts (hierarchical custom post type) that have children but are NOT top level?
- What is the correct term for a tool that filters content based on metadata?
- CPT Archive pre_get_posts not working?
- Pagination on search results page
- Ideas on how to organize a project [closed]
- Best way to create a search for custom post type by custom field values
- Filtering custom posts by custom fields (ACF) [closed]
- Searching post types
- Blank search results on custom search
- Multi Parameter search with custom post type category and tag
- CPT, meta-data, url parameter
- Limit search field to just search a custom post type with custom fields
- Search CPT Title AND Meta
- pre_get_posts works in post type archive but not in single post
- Building a Data Intensive Website with WordPress
- Display future posts in search
- Redirecting search to specific templates with $_GET[“post_type”]
- Modifying search results based on post_type
- Search custom type post
- How to Implement Search Functionality?
- How to have multiple search result pages in wordpress with taxonomy terms listed
- How to use pre_get_posts on archive page custom post type
- WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
- Is it possible to get the specific content on the search page?
- Order posts by taxonomy terms
- Change search query in wordpress custom post type
- Search for custom field input of a custom post type in ajax live search
- Query to Exclude Child Pages from Custom Post Type Archive
- Create a post automatically if search result has zero results
- How do I troubleshoot pre_get_posts with Debug Bar?
- Creating a custom WP query for a Custom Post Type
- In the php, how can I have a category of a custom post type display?
- Search Function not searching correct custom_post_type even though post_type is defined in search args
- Search only one custom post type
- How to hide private posts even if user is admin
- WP_List_Table Inside Metabox Not Working on Clicking Search Button
- Query first and last name from custom post type
- Custom Post type doesn’t appear in search results
- search results to show individual ACF fields from inside custom posts
- Display Specific Posts at Start of Loop
- post_type incorrect for custom post type
- Live search by custom tag
- List all posts associated under custom taxonomy
- Custom search for a custom post type in WordPress
- how to create custom taxonomy drop downs for parents and child
- Advanced search form with multiple custom fields
- Custom Archive – hide posts until a search is made?
- Search in multiple specific post types
- Set different posts_per_page for custom post type/taxonomy
- I can not display search template created from a post type custom
- Creating a search results page from a custom post type in a plugin?
- CPT year wise archive based on custom date Field
- Apply pre_get_posts to specific custom post type in the admin area
- Search custom post type result in same template page
- pre_get_posts gives 404 error on Custom Post
- Display result as “prefix+ID” and show in the search result as bookcode
- Include images from pages in wp search.php results in default wp search
- Search facility with directories
- Create Second Search Page Only for Custom Post Type
- Meta query broken since 4.7.4 Update
- custom search form for custom post
- Custom post url in search.php isn’t the correct rewrited url
- custom search results – order results differently by post type
- What’s the most efficient way to get two queries based on an if statement?
- Conditional posts in WP_query for search
- Post search not looking at post title since 4.4.2 upgrade
- Pre_get_posts comparison with custom field doesn’t work