March 2020
Beginner
660 pages
18h 28m
English
Sometimes we may need multiple searches on the same site to handle advanced requirements. Consider a scenario where we created a forum with bbPress. Assume that we want to add search functionality to the forum and a topics page for only searching the content from the custom post type. In this case, we can add multiple search forms and add the search URL with a dynamic URL parameter. Let's add a dynamic parameter called search_type to the URL:
if(isset($_GET['search_type'])) { $type = $_GET['search_type']; if($type == 'book') { $query->set('post_type',array('book')); } }
Now, if we edit the URL to http://www.yoursite.com?s=searchtext$search_type=book, the results will only contain books. ...
Read now
Unlock full access