I am new to coding a WP_QUERY and I tried a few things with it but it doesn't seem to work. Right now (you can see the page here: http://boomerang.mannydesigns.co/artistes/parcourir/musique/ )
I need to reorganize the ordering of these artists by a custom field I added (with ACF) name exclusif which is a selection field with 3 choices.
Is it possible to do so without doing a WP_QUERY & simply adding to the current code (which is the usual post loop)?
/**
* Alters queries
*/
add_action( 'pre_get_posts', 'wp_order_artists' );
function wp_order_artists( $query ) {
// don't run on the backend
if ( is_admin() )
return;
// Only run on post types artists
if ( is_post_type_archive('artists') && $query->is_main_query() || $post_type == 'artists' ) {
$query->set( 'orderby', 'meta_value' );
$query->set( 'meta_key', 'exclusif' );
$query->set( 'order', 'DESC' );
}
return;
}
if ( have_posts() ) : ?>
<div class="remix_items grid clearfix <?php echo $artists_col; ?>">
<?php while ( have_posts() ): the_post(); ?>
<a class="item<?php $i++; echo ($i % $artists_col_num === 0) ? ' last_item' : ''; ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark">
<figure class="effect-bubba">
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('type_cover');
} else {
echo '<img src="" alt="'.the_title().'">';
} ?>
<figcaption>
<h2><?php the_title(); ?></h2>
</figcaption>
</figure>
</a>
<?php endwhile; ?>
</div>
pre_get_posts
toquery_posts
query_posts
is the WRONG WAY to run a query. Please search this site, I really do think we have said enough aboutquery_posts
$wp_query
if you are breaking it withquery_posts
. It is like buying a new car for work, then driving it into a wall , scrapping it, for no apparent reason at all