Forums › Forums › Search & Filter Pro › Keyword search in titles only?
- This topic has 6 replies, 4 voices, and was last updated 1 year, 3 months ago by Trevor.
-
Trevor(Private) November 9, 2020 at 11:51 am #265580
Our plugin does not directly allow you to do text searches of individual Post Meta (custom fields) and Taxonomy (Category, Tags and Taxonomies) data/terms. The Search & Filter Pro Text Search field uses the standard WordPress search, so looks only in the Post Title and Content. To help you control this better, on the form’s Advanced settings tab you will see 2 settings for Relevanssi.
The documentation for this is here:
https://www.designsandcode.com/documentation/search-filter-pro/3rd-party/relevanssi/
You would need to install and activate the free Relevanssi plugin as well.
Then set Relevanssi up and build its index (make sure it is indexing the desired post types, custom fields AND any taxonomy that you want to search).
To restrict to Title only, please see this post:
https://support.searchandfilter.com/forums/topic/search-and-filter-only-in-title/#post-93961
Trevor(Private) September 20, 2021 at 10:01 pm #276331Please note that these support forums are now closed. If you require support, please raise a support ticket through Your Account.
Post Meta (custom fields), as the previous post I made on this ticket says, can already be searched using the Relevanssi option.
Anonymous(Private) August 1, 2023 at 9:47 am #276839Here’s a function for functions.php that will enable searching by title only, in various post types, without installing any other plugins. Hope this helps!
/** * Fix search results in admin to search by page title only * Modified from: https://developer.wordpress.org/reference/hooks/posts_search/ * * @param String $search * @param Object $wp_query Object * @return void */ function __search_by_title_only( $search, $wp_query ) { global $wpdb; $enabled_post_types = array( 'post-type-slug', 'another-post-type', ); if ( empty( $wp_query->query_vars['post_type'] ) || ! in_array( $wp_query->query_vars['post_type'], $enabled_post_types ) ) { return $search; // skip processing - not an enabled post type } $q = $wp_query->query_vars; $n = ! empty( $q['exact'] ) ? '' : '%'; $search = $searchand = ''; if ( empty( $q['search_terms'] ) ) { $q['search_terms'] = array(); } foreach ( (array) $q['search_terms'] as $term ) { $term = esc_sql( $term ); $search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')"; $searchand = ' AND '; } if ( ! empty( $search ) ) { $search = " AND ({$search}) "; if ( ! is_user_logged_in() ) { $search .= " AND ($wpdb->posts.post_password = '') "; } } return $search; } add_filter( 'posts_search', '__search_by_title_only', 1000, 2 );
-
AuthorPosts