title: php | wordpress | sort array of values
body: <p>I'm working in Wordpress with a custom post type of ''publications."  Originally, each "publication" was assigned to a single "category," and getting them to display by category was simple...</p>
  
  <pre><code>$args = array( 'post_type' =&gt; 'publications', 'meta_key' =&gt; 'publications_category', 'orderby' =&gt; 'meta_value', 'order' =&gt; 'ASC');
  $loop = new WP_Query( $args );
  </code></pre>
  
  <p>Then the client decided they wanted to assign the same "publication" to multiple "categories," and my meta_key became an array.  And now I can't get the "publications" to sort alphabetically by "category."</p>
  
  <p>Because my meta_key is now an array, I removed the 'meta_key', 'order_by' and 'order' from the query. Here's what I have been testing...</p>
  
  <pre><code>&lt;?php
  $args = array( 'post_type' =&gt; 'publications');
  $loop = new WP_Query( $args );
  while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();
  $cp_category = get_post_meta($post-&gt;ID, 'publications_categories', true); // assign a var to the array
  foreach ($cp_category as $category) { // iterate through the array
  the_title();  // print the title
  echo '&lt;br&gt;&lt;br&gt;' . $category . '&lt;br&gt;&lt;br&gt;'; //  print the category
  }
  endwhile;
  ?&gt;
  </code></pre>
  
  <p>I have tried various sort() functions on the array with not luck.</p>
  
  <p>There are six categories. The values are strings: 'cabg_vs_opcab', 'high_risk_patients', 'mortality_and_morbidity', 'stroke', 'clampless_beating_heart', and 'economics.' </p>
  
  <p>Here is what the output looks like.  I added a print_r() to diplay the array above each entry:</p>
  
  <pre><code>http://offpump.com/clinical-publications/
  </code></pre>
  
  <p>All I want to do is order the entries by their category so I'm hoping there is a way to do that.</p>
  
  <p>Thanks for any help or suggestions!</p>