WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Reverse post order with 2 loops on a page (2 posts)

  1. RETALI8
    Member
    Posted 1 year ago #

    Hi,

    On a page for my record label I have 2 loops on the one page, displaying a custom post type called 'releases'.
    I'm using the advanced custom fields plugin, and depending on whether a record has a value of out now, or coming soon depends which of the loops it will display in.

    Both loops start like this:

    <?php
    // args
    $args = array(
    	'numberposts' => -1,
    	'post_type' => 'releases',
    	'meta_key' => 'whether-release',
    	'meta_value' => 'outnow'
    );
    $the_query = new WP_Query( $args );
    ?>
    
    <?php query_posts($query_string . "&order=ASC", 'post_type=releases'); ?>
    <?php if( $the_query->have_posts() ): ?>
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    The first loop works correctly, however in the second loop on the page, it is displaying in the standard most recent back to oldest order (thus ignoring the &order=ASC )

    I am still learning PHP so if there is a more efficient way to do this that would also be welcome.

  2. RETALI8
    Member
    Posted 1 year ago #

    Did I mention I'm still learning php -.-'

    Fixed:

    <?php
    // args
    $args = array(
    	'numberposts' => -1,
    	'post_type' => 'releases',
    	'meta_key' => 'whether-release',
    	'meta_value' => 'outnow',
    	'order' => 'ASC'
    );
    $the_query = new WP_Query( $args );
    ?>
    
    <?php if( $the_query->have_posts() ): ?>
    		<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic