so i'm new wordpress , such i'm not entirely sure how things work it. 1 of problems having default search feature treats pages , posts same.
for example, have page called java, have several posts titled learning java #... if search java, page comes last item , posts come before it. i'm wondering if there way tweak search have pages listed first.
also, i've googled bit , have seen supposed php fixes problem, said, i'm new wordpress i'm not sure i'll editing in php. appreciated, , if comment, please treat me real beginner , break things down can understand better.
you need put code in function.php
:
function change_search_result_order($query) { // check if current page search page if ($query->is_search) { // specify orderby , order, ordering slug of post_type: page > post $query->set('orderby', 'post_type'); $query->set('order', 'asc'); }; return $query; } add_filter('pre_get_posts', 'change_search_result_order');
by default search function work post type, , can specify in want make search:
$query->set('post_type', array('page','post'));
hook pre_get_posts
fired before posts, need modify it. , set arguments, posts specific criteria.