Forums

How change search results order to show Pages first, posts second (1 post)

  1. vytaulla51
    Member
    Posted 3 months ago #

    Hi:
    WordPress search results are based on date. My website (a business site) has several static pages that discuss services AND we have a blog (which is not the homepage). Site uses a custom theme that I built, and the search.php comes from the old Kubrick theme.

    When you do a search, the "page" results always appear last and the blog post results appear first (since they are "fresher"). I would like to reverse that. The blog posts are lighter in nature -- the page info. is almost always more "relevant" than the blog posts.

    Here's my current code:

    <?php if (have_posts()) : ?>
    <div class="center">
    <div class="padding-bottom">
    <h1><?php _e('Our Search Results', 'kubrick'); ?></h1>
    </div>
    </div>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <div <?php post_class(); ?>>
    <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h3><?php the_excerpt(); ?>
    </div>
    
    <?php endwhile; ?>
    
    <?php else : ?>
    
    <h2 class="center"><?php _e('No luck. Try again?', 'kubrick'); ?></h2>
    <?php get_search_form(); ?>
    
    <?php endif; ?>

    Could I add something in there that would filter the results and put pages first?

    ThankS!

Reply

You must log in to post.

About this Topic

Tags