title: WordPress Orderby Last Word In Title
body: <p>I have a custom post type of "staff". I need to get this to display the staff alphabetically by last name on the page. I know a work around would be to use custom meta boxes and break up first and last names into two fields but I'm trying to avoid that as that seems very hackish and not as clean as just using the title field.</p>
  
  <p>I have a shortcode working that will show the custom post type with the staff "type" taxonomy attribute requested. Here is an example:</p>
  
  <pre><code>[staff type="local"] 
  </code></pre>
  
  <p>I can't just assume that it's the second word in the title that I want since some staff are couples and will have both of their names listed like: "Bob and Cindy Smith".</p>
  
  <p>Here is the shortcode that I have so far.</p>
  
  <pre><code>function get_staff($atts) {
      extract( shortcode_atts( array( 'type' =&gt; 'international' ), $atts ) );
      $loop = new WP_Query(
          array (
              'post_type' =&gt; 'staff',
              'orderby' =&gt; 'title',
              'staff-type' =&gt; $type
          )
      );
  
  if ($loop-&gt;have_posts()) {
      $output = '&lt;div class="staff"&gt;';
  
      while($loop-&gt;have_posts()){
          $loop-&gt;the_post();
          $meta = get_post_meta(get_the_id());
  
          $output .= '
              &lt;div class="staff" style="float: left; display: block; border: 1px solid #CCC; margin: 10px; padding: 12px; background-color: #eee;"&gt;
                  &lt;a href="' . get_permalink() . '"&gt;
                      ' . get_the_post_thumbnail($post-&gt;ID, 'thumbnail') . '&lt;br /&gt;
                  ' . get_the_title()  . '&lt;/a&gt;&lt;br /&gt;
                  ' . get_the_excerpt() . '
              &lt;/div&gt;
          ';
      }
      $output .= "&lt;/div&gt;";
  } else {
      $output = 'No Staff Meet This Criteria Yet.';
  }
  
  return $output;
  };
  
  add_shortcode('staff', 'get_staff'); 
  </code></pre>
  
  <p>This works great but is missing the alphabetizing by last name.  Thanks for any help you can offer. This is my first real attempt at an elaborate shortcode so please be a little specific with your answer.</p>