The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › Back End › Nested Loops and Shortcode – WordPress
I’ll do my best to explain.
I want to be able to place a testimonials box anywhere in my page from the WordPress editor using shortcode – [testimonials_box]
[testimonials_box]: Queries a custom post type = testimonials.
Since it’s added in a page loop it’s a nested loop and I can’t get it to work.
How would I go about doing this?
— Start Page Loop —
if (have_posts()) : while (have_posts()) : the_post();
— Start Custom Post Type Loop —
$query = new WP_Query( array ( ‘post_type’ => ‘testimonials’ ) ); while ( $query have_posts() ) : $query->the_post();
— End Custom Post Type Loop -;
else : ?>
–End Page Loop —
Basically, how do I query a custom post type, inside of a loop. And then when it’s done, return back to the original loop.
How are you echoing the shortcode in your PHP?