search result page result display first then post
-
Hi everyone
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 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘search result page result display first then post’ is closed to new replies.