I can't get the order of my posts (organized by custom tax terms) to come out right in my loop.
I made a custom post type of 'staff', in staff there is a custom taxonomy of 'staff-title'.
I added terms (similar to categories to keep the UI clean for the client) such as 'editor-in-chief', 'managing-editor', 'poetry-editor', etc. The idea is that the client can go into the 'staff' post type, create posts that are named after the employee and then check which position they hold and then the posts will be displayed in the proper order (displaying posts by running down the chain of command).
Here is the function creating my custom tax in functions.php:
function add_custom_taxonomies() {
// Add new "Locations" taxonomy to Posts
register_taxonomy('staff-title', 'staff', array(
// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Staff Titles', 'taxonomy general name' ),
'singular_name' => _x( 'Title', 'taxonomy singular name' ),
'search_items' => __( 'Search Titles' ),
'all_items' => __( 'All Titles' ),
'parent_item' => __( 'Parent Title' ),
'parent_item_colon' => __( 'Parent Title:' ),
'edit_item' => __( 'Edit Title' ),
'update_item' => __( 'Update Title' ),
'add_new_item' => __( 'Add New Title' ),
'new_item_name' => __( 'New Title Name' ),
'menu_name' => __( 'Staff Titles' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'locations', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/locations/"
'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
),
));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
Here is my WP_Query on the staff page...
$args = array(
'post_type' => 'staff',
'tax_query' => array(
array(
'taxonomy' => 'staff-title',
'field' => 'slug',
'terms' => array('editor-in-chief', 'managing-editor', 'fiction-editor', 'poetry-editor', 'nonfiction-editor', 'production-manager' )
)
),
'posts_per_page' => '-1',
'order' => 'ASC',
'orderby' => 'meta_value_num'
);
$my_query = new WP_Query( $args );
The tax_query 'terms' => array(...) has the terms (staff positions) listed in the order they should be displaying but this isn't the case.
Visiting the staff page the posts are displaying in this order, which is the WRONG order:
Editor in Chief - Ching-in Chen
Managing Editor - Shanae Martinez
Production Manager - Matthew Morris-Cook
Nonfiction Editor - Kate Nesheim
Poetry Editor - C. McCallister Williams
Poetry Editor - Kara van de Graaf
Fiction Editor - Loretta McCormick
Fiction Editor - Mollie Boutell
Here's the CORRECT order just for reference (same order as the tax query terms array):
Editor in Chief - Ching-in Chen
Managing Editor - Shanae Martinez
Fiction Editor - Loretta McCormick
Fiction Editor - Mollie Boutell
Poetry Editor - C. McCallister Williams
Poetry Editor - Kara van de Graaf
Nonfiction Editor - Kate Nesheim
Production Manager - Matthew Morris-Cook
I put up the staff names as they are the title of the individual posts and I thought they might be a part of the problem.
Anyone have any ideas on how I could fix this? If you need more information let me know I'd be happy to provide. Thanks in advance!