WordPress.org

Ready to get started?Download WordPress

Forums

Sort posts by name, but exclude "the," "a," "an" (2 posts)

  1. Michael
    Member
    Posted 8 years ago #

    I am using WordPress to host a conference website at my university, and each breakout session has its own post. I am listing the posts alphabetically by title, using the "orderby=title" attribute for the query_posts tag.

    Is there an easier way to exclude "the," "an," "a," and quotation marks (left single & left double) from the alphabetical sort order? Without my ugly hack (below), posts with "The" get lost among the Ts, and quoted titles get dropped to the bottom, etc.

    My current method creates problems with titles in the head tags and with the DD Sitemap Generator Plugin. Plus it may create confusion with our non-technical content creators.

    My ugly hack involves renaming the post title without the leading characters (ex. "The Post Title" becomes "Post Title"). I then save the leading characters as a custom field (ex. "The "). Then I reassemble the entire post title by retrieving the custom field with the c2c_get_custom tag from Coffee2Code's Get Custom Fields plug-in, which only works inside The Loop.

    It would be ideal if I could find a method that allows me to just keep "the," "an," "a," etc. in the post title.

  2. petit
    Member
    Posted 8 years ago #

    I'm not at all sure about this, but maybe you could use
    <?php query_posts('cat=10&showposts=-1&orderby=title&order=ASC'); ?>
    and instead of orderby=title, use orderby=post_slug.
    If this is possible, you would give slugs to your posts in such a way that you get the order you wish.

    Somebody deeper immersed in the inner workings, please jump in her ;)

Topic Closed

This topic has been closed to new replies.

About this Topic