WordPress.org

Ready to get started?Download WordPress

Forums

Alphabetizing posts in one category only,by custom field (5 posts)

  1. anitraweb
    Member
    Posted 1 year ago #

    I maintain a site with pages on individuals, locations,and news categories. I want to display the names in alphabetical order, by last name, and I have added a custom field,lastname, in order to do so.

    I get partway there by inserting
    <?php $posts = query_posts( $query_string . '&orderby=lastname&order=asc'); ?>
    in archive.php just before The Loop. Two problems remain:

    1. All categories are sorted. I only want the Names in alphabetical order. I want the other categories in default latest-first date order.
    2. If I use order=asc, the names sort in descending order (z-a) within the date posted. October 2011 Z through A; then October 2012 Z through A; etc. If I use order=desc, they list only by date, with no sorting on name at all.

    If you want to see it in action, the site is http://fallenleaves.org/

    How do I get the Names category to ignore the date of posting entirely, and sort only by last name, a-z, while Locations and News sort by date posted, descending?

  2. IMICreation
    Member
    Posted 1 year ago #

    you can get the id on archive page of names category and insert the condition for that
    if names id is{
    <?php $posts = query_posts( $query_string . '&orderby=lastname&order=asc'); ?>
    }else{
    your normal query_posts for other categories
    }

  3. anitraweb
    Member
    Posted 1 year ago #

    Thank you. That narrowed the sorting to just the Names.

    I'm still getting peculiar results from the sort, as if the posts are sorting by date first, then by lastname within the date, and sorting lastname descending, instead of ascending.

  4. anitraweb
    Member
    Posted 1 year ago #

    It also sorts date descending (oldest first).

  5. anitraweb
    Member
    Posted 1 year ago #

    I got this sort working last October. This month I added seven names,and they don't show up at all in the "Names" category list. They can found by search, but not by clicking the alphabetized Names list.

    The Names category shows the correct total of records (116)but does not display them all when clicked; it omits the last seven entries.

    All of the last seven entries have the category "Names" and an entry in the lastname custom field.

    What are possible reasons for this?

    http://fallenleaves,org/

Topic Closed

This topic has been closed to new replies.

About this Topic