I’ve got a wordpress loop Im working on for a sports website that I’m having an issue with figuring out.
I’ve created a custom post type called Players
I’ve created a custom Taxonomy called Position (forward, defense, goalie)
I’ve also got some custom meta boxes one being jersey number.
I trying to split the page into 3 sections based on position so I’ve tried to create a query for each loop. I’ve written this.
$posts = new WP_Query( array(
'post_type' => 'players',
'showposts' => 10,
'tax_query' => array(
'taxonomy' => 'position',
'field' => 'slug',
'terms' => 'forward')
));
The second part of the question I had was if it was possible to arrange this query by a meta box value, I ideally would like to orderby jersey number.
I’ve tried a few suggestions but in every loop I keep getting all the posts from players.
$posts = new WP_Query( array(
'post_type' => 'players',
'showposts' => 10,
'tax_query' => array(
'taxonomy' => 'position',
'field' => 'slug',
'terms' => 'forward')
));
while ( $posts->have_posts() ) : $posts->the_post(); ?>
<tr class="player">
<td class="leftBrdr"><?php the_title(); ?></td>
</td>
</tr>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
you can also do order by ‘menu order’ which is available for pages and your cpt if it is defined as ‘hierarchical’ => true in the register_post_type.