简体   繁体   中英

Multiple custom post loops on page

I'm unable to get a second or third loop to display after the first loop is displayed. I've been trying different things for the past two hours but I'm running out of ideas.

This is what I have right now --

<?php
$type = 'new_trucks';
$args=array(
 'orderby' => 'rand',
 'post_type' => $type,
 'paged' => $paged,
 'posts_per_page' => 3,
);

$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query($args);
?>

<?php while (have_posts()) : the_post(); ?>
...
<?php endwhile; /* End loop */ ?>
<?php wp_reset_query(); ?>

The second loop is like so and is right under the first loop shown above...

<?php
$type = 'used_trucks';
$args=array(
 'orderby' => 'rand',
 'post_type' => $type,
 'paged' => $paged,
 'posts_per_page' => 3,
);

$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query($args);
?>

<?php while (have_posts()) : the_post(); ?>
...
<?php endwhile; /* End loop */ ?>
<?php wp_reset_query(); ?>

In my attempts to duplicate that in the same page with a different type set, the second loop is not displaying at all. If I erase the first loop, it works. I'm hoping someone can please provide some guidance.

Thanks!

<?php
$type = 'new_trucks';
$args=array(
 'orderby' => 'rand',
 'post_type' => $type,
 'paged' => $paged,
 'posts_per_page' => 3,
);

$wp_query = null;
$wp_query = new WP_Query($args);

?>

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
...
<?php endwhile; /* End loop */ ?>
<?php wp_reset_query(); ?>

is how I have done it in the past

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM