-1

I have a Query:

<?php
                    $feature_big = array(
                        'posts_per_page'    => '1',
                        'meta_key' => $count_today,
                        'orderby' => 'meta_value_num'
                    );
                    $wp_feature_big = new WP_Query( $feature_big );
                ?>
                <?php if( $wp_feature_big->have_posts() ) : while( $wp_feature_big->have_posts() ) : $wp_feature_big->the_post(); ?>
                    /----------------------------here------------------/
                <?php endwhile; endif?>

Now, i want change value (posts_per_page, meta_key,...) in 'here'. Is it possible? And How? Thank you! Sorry my English :)

9
  • Yes it's possible, you can change it. Commented Nov 23, 2016 at 5:46
  • How? Thank you so much Commented Nov 23, 2016 at 5:47
  • What values do you want to set for those keys? Commented Nov 23, 2016 at 5:48
  • eg: 'posts_per_page' => '1', here you can change value 1 to 10 to show 10 posts per page Commented Nov 23, 2016 at 5:49
  • you will have to initiate new WP_Query object inside while loop with new args. then fetch all posts again inside that, need complete explanation ? Commented Nov 23, 2016 at 5:51

1 Answer 1

0

You can run multiple nested WP_Queries as long as you reset_postdata() to get the outer loop back on track.

$query_args = array (
    'posts_per_page' => '1',
    'meta_key'       => $count_today,
    'orderby'        => 'meta_value_num',
);

$outer_query = new WP_Query( $query_args );


while( $outer_query->have_posts() ) :

    // conditional if
    if( true ) {

        // change the query arg in the inner loop
        $query_args[ 'meta_key' ] = 'something_else';
    }

    // start an inner query with adjusted params
    $inner_query = new WP_Query( $query_args );

    // nested loop
    while( $inner_query->have_posts() ) :

        // ...

    endwhile;

    // After looping through a nested query, this function restores the $post global to the current post in this query.
    $outer_query->reset_postdata();

endwhile;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.