WordPress.org

Ready to get started?Download WordPress

Forums

Search Results in Alphabetical or Relevant Order? (8 posts)

  1. jsuko
    Member
    Posted 8 years ago #

    I hope this isn't in the forums somewhere else, but I've been wondering if someone could help me with getting my search results to display in alphabetical (title) and not chronological order. What or how can this be done?

    Also, is there a way to search based on relevance?

    Any help is appreciated, as I'm getting pretty frustrated. Thanks!

  2. Kafkaesqui

    Posted 8 years ago #

    If you have a search.php template with your theme, insert this in it just above The Loop:

    <?php query_posts('orderby=title&order=ASC'); ?>

    If you don't have a search.php, you can copy the theme's archive.php (or if *that* is not available, index.php) for it. Alternatively, you could use the following in archive.php/index.php:

    <?php if(is_search()) {
    query_posts('orderby=title&order=ASC');
    } ?>

    More info on query_posts():
    http://codex.wordpress.org/Template_Tags/query_posts

    "Also, is there a way to search based on relevance?"

    Plugin you may want to check out:
    http://www.semiologic.com/projects/search-reloaded/

  3. jsuko
    Member
    Posted 8 years ago #

    thanks for the direction!

  4. Beel
    Member
    Posted 8 years ago #

    Nice Kafka, though I don't understand the relevance. If I am searching for something on "blah", the title would be irrelevant. Just because it starts with an "A" doesn't mean it contains the information for which I am looking ;-).

  5. snoogly
    Member
    Posted 8 years ago #

    Hmmm.

    Adding
    <?php query_posts('orderby=title&order=ASC'); ?>

    does get the search results in alphabetical order, but the navigation to next and previous search results pages no longer works. I can't see more than the first page of search results.

  6. snoogly
    Member
    Posted 8 years ago #

    Is there any documentation for that plugin? I can't find any ways to configure it.

  7. snoogly
    Member
    Posted 8 years ago #

    I tried adding this to search.php

    <?php
    // we add this, to show *all* posts sorted
    // alphabetically by title
    $posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=-1');
    // here comes The Loop!
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    (found at: http://codex.wordpress.org/Alphabetizing_Posts) but I get the same non-functioning next and previous buttons. Does this indicate that something is broken?

Topic Closed

This topic has been closed to new replies.

About this Topic