solutionweb

WordPress Common Errors and Solutions

WordPress code to enhance the search function, classification, labels, user candidates.

We know that the default WordPress only retrieves articles and pages, and will not retrieve other things such as users, categories, tags, etc. For ordinary blogs, only retrieving articles is enough, and even searching is redundant. However, for sites with more content, the search function is very useful to display functions such as classification, labels and user candidates.

WordPress provides a plug-in search everything. I have downloaded and checked the code of this plug-in, all of which are sql written by myself. In fact, many parameters of WordPress have search parameters, so we can call the corresponding functions directly.

You can personally test the specific effects, enter keywords and click search, and then enter the search page by category, label and user candidate words.

WordPress code to enhance the search function, classification, labels, user candidates.

Let’s show you a few commonly used codes. The following codes need to be used in the search template, that is, search.php. get_search_query () can get the search keyword. If you want to use it in other places, you can replace the search parameter with something else.

Classified search
get_search_query());
$categories = get_categories($arg);
if(! empty($categories)){
echo ‘

‘;
}
? >
User search
get_search_query());
$users = get_users($arg);
if(! empty($users)){
foreach( $users as $user ){

}
}
? >
Search consumes system resources very much. Some time ago, because I received a CC attack, I had to close the search that comes with wordpress and thank you again for a search with anti-CSRF. If you have a lot of visits and the server is not powerful, I suggest using Baidu or google search.

Back to top