search result page first then post
-
I tried to add a function for WP default search, I will like to make it result to shoe page items first, then post items, but it’s not quite working yet.
I’m not using any plugin for search.
Here’s my code:First one
<?php function filter_search($query) { if ($query->is_search) { $query->set('post_type', array('page', 'post')); }; return $query; }; add_filter('pre_get_posts', 'filter_search'); ?>
Second one I tried:
<?php function filter_search($query) { if ($query->is_search) { $query->set('post_type', array( 'post_type'=>'page', 'orderby' => 'title', 'order' => 'DESC', ) ); } else { $query->set('post_type', array( 'post_type'=>'post', 'order' => 'DESC', ) ); }; return $query; add_filter('pre_get_posts', 'filter_search'); ?>
Thanks for the help!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘search result page first then post’ is closed to new replies.