Answer the question
In order to leave comments, you need to log in
How to display search results for sections in wordpress?
I did a search on the site, in the search results you need not just dump posts, but split them into categories, for example:
In the news: Post1, Post2, Post3
In events: Post5, Post8
In the structure: Post19
Well, and so on, I did not find this in the docks
Answer the question
In order to leave comments, you need to log in
FIND_IN_SET()
This is at least the third time I've answered a similar question where people can't google this function.
First, look towards fulltext search (there is a lot of information in the search).
If it doesn't work, you can do something like this -
$words = array('Привет', 'привет', 'Хай', 'хай', 'Хэй', 'Хэллоу');
$impl = implode('%', $words);
$where = "TEXT LIKE '%{$impl}%'";
like this
select *
from <table>
where upper(text) like upper('%Привет%' )
or upper(text) like upper('%Хай%' )
or upper(text) like upper('%Хэй%' )
or upper(text) like upper('%Хэллоу%' )
There is an array of words (s)
then just
save this array to a temporary table
and join your table with the
PS array table if the array is large - do not forget to make an index for it on the temporary table
In my opinion, a simple solution would be:
In the search.php template (if it does not exist, you need to create it), in the main while loop, add the data to an array, grouping it according to the necessary criteria (news, events).
How to create grouping conditions is a question for the structure of your site, what types of posts, taxonomies are there. Immediately add the necessary record data to the array - titles, links, etc.
Then, through the loop, output the already grouped data to the template.
There is a question about how to do pagination correctly. I would limit the search result to a certain number of entries, for example 100. And I would display everything on 1 page. This is the easiest option.
There are many options on how to implement.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question