I figured it out, thanks
function my_search_pre_get_posts($query)
{
if($query->query_vars['s'] != '' && is_search())
{
if(absint($query->query_vars['s']))
{
$query->set('p', $query->query_vars['s']);
$query->set('post_type', ['property']);
// Reset the search value
$query->set('s', '');
}
}
}
// Filter the search page
add_filter('pre_get_posts', 'my_search_pre_get_posts');
A very good learning of WordPress functionality.
Related Posts:
- How do I query for posts by partial meta key?
- WP_Query orderby date not working
- meta_query where value is equal to given value
- Query by meta_key and order by meta_value_num return orderby date
- WP Query post meta value
- How to exclude products by tag from woocommerce shop page?
- Filtering posts by custom field value not working
- wpdb get results doesn’t work with variable
- WordPress WP_Query orderby being overwritten
- Multiple meta queries but arrange by specific meta value order
- Custom pagination with WP_Query generating 404 error
- Query post with meta_query where date is not in future
- Apply CSS class to every second database record [closed]
- pre_get_posts order by not working
- merge two query arguments into one WP_Query call
- How do I change the order (ASC and DESC) in the following retrieval method using WP_Query?
- How to get all child pages in their parent page?
- How to display summary content from a Page (Not a Post) on another page
- Custom Search Not Consistent with Results
- how do we display all posts from a particular category in homepage?
- Display both standard posts in a specific category along with a custom post type in a single loop?
- Orderby is working with one query but not with other
- meta_query in WP_Query value is not accepting array
- Loop Split two Columns
- Search by post id in a specific page then auto-redirect to searched post
- Pretty urls for custom pagination
- WP_Query with ‘rand’, but equal number of posts from the taxonomy terms given
- use of 10 new WP_Query : loading too slow (with url) [closed]
- How to make a second query offset -2 from current post
- slow query – Search for Media Gallery
- How to not display tags with less than X posts
- WordPress has a list of reserved words, can I override them, to use one in a query string?
- Wp_query with 2 meta keys and array of meta values
- meta_query: check if number exists
- How to order WP_Query to group results?
- Search Page Returns Nothing
- Which meta_query and post_content blend is better in WP_Query, performance wise?
- WP Query causing timeout
- get term id from term name
- Problem with get_page_by_path() using with WP_Query
- Query where ANDing slug values not working
- Woo Commerce using WP_Query to get products that match price range, with an additional required product attribute
- change posts_orderby of the callback wp_query?
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- Content not displaying on paginated page
- show custom category posts from a custom post type
- how to load posts to a custom post template after using template_redirect or template_include
- 2 queries with counters
- WP Query / Meta Query [duplicate]
- Multiple Query_Posts
- WP_Query: attachment image in “full” size?
- Page template doesn’t display simple HTML if inserted into other page?
- Query multiple post types, but different order for each
- How to add date_query to meta_query array
- Order by the first array within a meta_query
- View list of custom posts within a date range relative to today’s date, based on a custom date field
- Multiple nested meta queries
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- Comparing Meta Field date in WPQuery using Meta_Query?
- Get categories within specific term
- Fix wp_term_relationships slow query in get_posts
- Custom query for custom post type not getting correct post ID
- How to merge these two post queries?
- How to search posts by title with special characters in WP_Query?
- How can I query a radius of coordinates?
- Query postmeta based on meta_value, return array of post_id
- WP_Query: Query posts only if their access is restricted to logged user’s role
- datetime picker, timestamps and meta queries
- Get specific value from variable to use in query
- WP_Query with meta_query won’t orderby
- Adding Category in WP_Query Not Working
- meta_query only check if both value are set
- Meta key in wp_query bug?
- display all posts from category with and without terms in chronological order
- How to create page that lists tags by initial letter?
- Seach and categories not working when ignoring sticky posts in main loop
- How can I create another instance of my custom shortcode
- How To Call WP_Query From A Subdomain?
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- WordPress: Cron locking and Queue
- Correct Way To Run Multiple Queries Sharing Some Base Data
- how to query for meta_value have array
- How to make the default WordPress search return borader results
- WP_Query shows all posts on single post pages
- Display Count of posts
- Show sticky post before other WP_Query
- List ALL posts within last week from current category on category page
- WP_Query on “property” in the options table
- Post OrderBy slow performance
- Dynamically name array in WordPress loop – add/get values
- Creating Custom Query
- WP_Query issues with argument posts_per_page
- Search (Custom Form, Custom Search Result)
- Hook to get the query result after listing posts
- Elementor custom query
- How do I subquery with custom meta fields?
- Show number of posts AND number on current page (cannot make it work)
- Advanced Search – Is this possible?