Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Show only results based on a number of words in the title
This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko 1 year, 5 months ago.
- AuthorPosts
- April 3, 2023 at 12:49 pm #42085
The website contains almost 2400 pages. With the search box we want to search by place name. For example Amsterdam. Only posts with the words ‘City Game’ in the title should appear in the search results. The other posts do not need to be displayed.
How can you set a filter that only posts with the title ‘City Game’ are displayed?Thanks in advanced!
April 3, 2023 at 1:09 pm #42090Hi,
Thank you for all the details!
Are there many other pages you don’t want to show? If there are only a few, then maybe you could try to exclude them via these settings.
Best,
If there are too many to exclude one-by-one, then are the pages categorized in any way? Excluding or inlcuding by categories is the easiest way to restrict the results to specific taxonomy terms only.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 3, 2023 at 1:16 pm #42091Hi Ernest,
There are many other pages that we dont want to show. The pages don’t have a category like the posts.
The easiest way would be to include only pages that contain the words City Game.
Best,
Ivo VisserApril 3, 2023 at 1:26 pm #42092Okay. That is not going to be super easy, it will definitely require some custom coding to push an argument for the search phrase. Enforcing an restriction on the searched fields is generally not the best idea, but there is probably a way to do this.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
Best,add_filter( 'asp_search_phrase_before_cleaning', 'asp_search_phrase_before_cleaning_add', 10,3 ); function asp_search_phrase_before_cleaning_add($phrase) { return '"city game" ' . $phrase; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 3, 2023 at 1:32 pm #42093Thank you very much Ernest. This feature does exactly what I want.
Best,
Ivo VisserApril 3, 2023 at 2:16 pm #42094You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.