Forums

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

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #168700
    Steven Morgan
    Participant

    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.

    Page:

    Title
    Content

    [testimonials_box]

    More Title
    More Content

    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();

    echo it

    endwhile;
    — End Custom Post Type Loop -;

    endwhile; ?>
    else : ?>
    endif; ?>
    –End Page Loop —

    #168702
    Steven Morgan
    Participant

    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.

    #168705
    Alen
    Participant

    How are you echoing the shortcode in your PHP?

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.