Tuesday, 10 September 2013

WordPress 'orderby' last word in post title

WordPress 'orderby' last word in post title

I have a shortcode that lists post titles in a category. The titles are
people's names. I need to order the posts by last name (or last word) in
the title. I've found other answers to this question, like these:
WordPress Orderby Last Word In Title and
http://wordpress.org/support/topic/sort-posts-alphabetically-by-last-name-or-last-word?replies=2
But neither had any effect. I'm clearly doing something wrong, but I don't
know what. Here is my shortcode code:
function rmcc_specialities_shortcode( $atts ) {
ob_start();
// define attributes and their defaults
extract( shortcode_atts( array (
'category' => '',
), $atts ) );
// define query parameters based on attributes
$options = array(
'attorney_specialty' => $category,
'post_type' => 'attorney',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1,
);?>
<h5>Contacts</h5>
<?php
// this is where I put the last name filter code - is that correct?
$my_query = null;
$my_query = new WP_Query($options);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br />
<?php
endwhile; } wp_reset_query(); return ob_get_clean();
}
add_shortcode( 'attorneys', 'rmcc_specialities_shortcode' );

No comments:

Post a Comment