• Hi all,

    I’m using WordPress as a CMS for a music agency at the moment, using custom-posts as a means of adding artists to the database. It’s been working great so far, but I’m scratching my head a little as the client would like the names of the artists to be arranged in alphabetical order by their last name.

    The artists’ names are currently added via the title attribute, so obviously WP can sort my posts out in alphabetical order easy peasy, but how on earth can I get it to do so by using the last name – ie the last word – of the title?!!

    The site (as yet unfinished) can be found at https://daviesmusic.com/

    Any ideas?!! I’m drawing a blank here I must confess…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Richard Sweeney

    (@theorboman)

    Hmm, I’ve tried using a custom-field to add the surname of the artist but I still can’t seem to get my artists in order! Here’s the code I’m using

    <ul>
      <?php
        $yell = new WP_Query(array('meta_key' => 'surname', 'post_type' => 'singer', 'voice' => 'soprano-voice', 'showposts' => '-1' , 'orderby' => 'meta-value', 'order' => 'asc' ));
        while ($yell->have_posts()) : $yell->the_post();
      ?>
      <li>
        <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>">
          <?php the_title(); ?>
        </a>
      </li>
      <?php endwhile; ?>
    </ul>

    I’ve also tried using 'orderby' => 'title' just for the hell of it! No joy…

    Help!

    Thread Starter Richard Sweeney

    (@theorboman)

    What a fool I’ve been! Was a mere slip of the wrist…

    Instead of meta-value it should of course read meta_value then all will be right with the universe once again.

    Mmm. Awesome. Now I’ve sorted my custom post-types by custom taxonomy and custom-fields! That’s a lot of customization! I heart WP 3.

    That’s just what I needed. Nice!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sort (custom) posts by last word in title’ is closed to new replies.