• 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 https://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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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
    }

    Thread Starter Anitra Freeman

    (@anitraweb)

    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.

    Thread Starter Anitra Freeman

    (@anitraweb)

    It also sorts date descending (oldest first).

    Thread Starter Anitra Freeman

    (@anitraweb)

    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?

    https://fallenleaves,org/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Alphabetizing posts in one category only,by custom field’ is closed to new replies.