In wordpress query, Can I single out the specific post by index number of the query result?

for example

            $args =  array( 
                'post_type' => 'headimages',
                'orderby' => 'menu_order',
                'order' => 'ASC'
             $package_query = new WP_Query( $args );
             $num = $package_query->post_count; ?>

so how do i display the second result or third result from this query? Can I do something like this?

<php $thirdresult = $package_query[2];>

please help.


The results of a query are stored as an array in the $posts property of the query object, so you can access the third result like so:

$package_query = new WP_Query( $args )
$third_result  = $package_query->posts[2];
  • Thanks, I was searching the net like three hours for this simple solution. You just saved my life. Thanks again. – Enam May 29 '19 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.