In WordPress 6.2+, within WP_Query
you can set search_columns
parameter (not documented at time of writing) to specify the fields to search:
$query = new WP_Query( array(
's' => 'search term',
'search_columns' => array( 'post_content', 'post_name', 'post_title' ),
) );
You can also use the post_search_columns
filter to adjust the search columns. You may need to use the wp_query_search_exclusion_prefix
filter to change the operator. See the definition for WP_Query::parse_search()
for more info.
For WordPress before 6.2, you’re likely limited to using the posts_where
filter.
Related Posts:
- How to print the excuted sql right after its execution
- Pagination with custom SQL query
- Return only Count from a wp_query request?
- how does $wpdb differ to WP_Query?
- Is it true $wpdb->get_results is faster than WP_Query in most cases?
- Query causing load because of SQL_CALC_FOUND_ROWS post counting?
- Use WP_Query with a custom SQL query
- How to make an activities stream mixing posts and comments?
- How can I connect to another WP database and use WP_Query?
- Get number of comments after modifying comment query
- How to change a custom query into a standard loop?
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Should close $wpdb via $wpdb->close()
- $wpdb->insert inserting two rows in database
- Get the Plugin Which Triggered a MySql Query in WordPress?
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Detect featured image among the attached images
- How would I format a query that depends on post parent taxonomy
- Mysql query LIKE not working
- Select from wp_post and multiple meta_value from wp_postmeta
- Order by custom table and multiplication
- How to correctly pass values to wpdb->prepare()?
- $wpdb select date range of posts
- What’s the purpose / logic of split_the_query in WP_Query->get_posts
- WPDB query – decrypting DB data
- How to delete taxonomy term when a wordpress user is removed?
- Custom Query num_rows returns wrong amount
- Getting post revision and printing them on the post content site
- Filtering posts from different categories into different section by doing WP_Query only once
- Iterating through $wpdb query without using get_results for large query results
- Query with search and subscribers only output
- wp_Qwery works to slow
- How to query custom post types with mixed AND & OR statements for custom fields
- Query most popular terms by taxonomy over 2 week period
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- Custom query: Get all posts that are from a certain category?
- How to access custom WordPress database tables
- How to pass orderby params to $wpdb->prepare()?
- Ajax future single post query doesn’t work when NOT logged in
- Conditional sorting with variable using WP Query
- Is it safe to access the underlying mysqli object from \wpdb for custom queries?
- Make a SQL query with wpdb in WordPress
- WordPress query posts with multiple post_meta data
- List of ways to access WordPress database?
- Specify strict ‘order by’ in WordPress query
- Does WordPress have something like Drupal’s DB API?
- get_post() is not returning correct value
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- get_var is neither a string, integer, or array …?
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- how to translate countries output from wp database?
- What’s wrong with this wpdb query?
- duplicated posts when using pagination
- Passing a SQL query to the WP Query
- Save queried result into database
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- How to get user avatar via WPDB
- In which file to use $wpdb and its functions for database operations and queries in wordpress?
- What argument does my function need to echo get_results() query results
- complex query question
- Select Unique Posts for a List of Tags
- How To Use WP_Query To Get The Custom Post type Posts With Keywords
- Include post_status check within $wpdb query
- wpdb get_results() returns only 2 rows
- Optimising amount of calls to custom fields
- pre_get_posts or $where, which one to use?
- Fire query on ajax post url page
- Slow getting posts from category
- Search Query that Includes Custom Table
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- WP_Query search by multiple meta key and distance
- Different sql queries count indicator on the main page [closed]
- wpdb LIKE request shows all database data
- Convert a WP Query into a simpler SQL query to fetch only COUNT of posts
- How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page
- how to use transient method?
- get_post_meta bringing back results, but $wpdb->postmeta doesn’t
- Is there another way to retrieve a post_id from post_meta other than a SQL query?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- How can I save an array from a random post sequence for later use?
- Why is WP-Query spelled like it is?
- WP_Query won’t retrieve raw HTML?
- Any number in meta key (wp query)
- Custom Metabox data slow query on Admin init
- Order by summing multiple values
- Understanding the orderby in WP_Query?
- complex get_posts() query to select child pages
- How can I change the term “Published” next to # of posts published on WordPress dashboard All Posts page?
- WP_query pagination on frontpage
- WP Query by 4 different taxonomies
- WordPress Query by Category using Post Slug
- WP Query for all events prior to current date
- Displaying posts from sub taxonomies only
- get term objects and post objects in query
- Object of class WP_Query could not be converted to int inside shortcode
- display post multiple times based on array of dates
- Add custom WP_Query after the first 3 posts
- Why won’t my paged wp_query work? [duplicate]
- Use meta query only 3 or more results?