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...
$args = array( 'post_type' => 'publications', 'meta_key' => 'publications_category', 'orderby' => 'meta_value', 'order' => 'ASC');
$loop = new WP_Query( $args );
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."
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...
<?php
$args = array( 'post_type' => 'publications');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$cp_category = get_post_meta($post->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 '<br><br>' . $category . '<br><br>'; // print the category
}
endwhile;
?>
I have tried various sort() functions on the array with not luck.
There are six categories. The values are strings: 'cabg_vs_opcab', 'high_risk_patients', 'mortality_and_morbidity', 'stroke', 'clampless_beating_heart', and 'economics.'
Here is what the output looks like. I added a print_r() to diplay the array above each entry:
http://offpump.com/clinical-publications/
All I want to do is order the entries by their category so I'm hoping there is a way to do that.
Thanks for any help or suggestions!