482 posts
  • Sells items exclusively on Envato Market
  • Has sold $1,000+ on Envato Market
  • Attended one of our Meetups around the world
  • Located in United Kingdom
+3 more
FlatKing
says

Hey everyone – Fingers crossed someone can help me here

I’m using a WP query to bring a loop for a custom post type within a shortcode.

I’ve got it bundled at the end into return $output;

$args = array( 'post_type' => 'news');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
        $output .= get_the_title();
        $output .= '<div class="entry-content">';
        $output .= the_excerpt();
        $output .= '</div>';
endwhile;

This is what’s being displayed http://prntscr.com/2qcn4a

If I change the_excerpt to get_the it just goes blank and doesn’t even echo the excerpt to a random place – http://prntscr.com/2qcnlc

Would love any help!!!

Quick Edit
Tried wrapping in tags
Tried global $post;
Tried get_the_excerpt($post->ID)
221 posts
  • Has been part of the Envato Community for over 4 years
  • Located in United Kingdom
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
NuclearThemes
says

Get the excerpt doesn’t accept any parameters (frustratingly). You need to use wp_trim_words and get_the_content to get the excerpt by ID.

67 posts
  • Has been part of the Envato Community for over 1 year
  • Sells items exclusively on Envato Market
DesignLinks
says

If the issue is that your loop content is being echoed on top of all page contents then wrap your loop code like this …

    ob_start(); 

    get_template_part( 'blog', 'index' );  // your loop here

    $return = ob_get_contents();
    ob_end_clean();
    return $return;

Hope it helps :)

482 posts
  • Sells items exclusively on Envato Market
  • Has sold $1,000+ on Envato Market
  • Attended one of our Meetups around the world
  • Located in United Kingdom
+3 more
FlatKing
says

If the issue is that your loop content is being echoed on top of all page contents then wrap your loop code like this …
    ob_start(); 

    get_template_part( 'blog', 'index' );  // your loop here

    $return = ob_get_contents();
    ob_end_clean();
    return $return;

Hope it helps :)

Is there a need to do the actual get template? or can I still just have the loop in there?

482 posts
  • Sells items exclusively on Envato Market
  • Has sold $1,000+ on Envato Market
  • Attended one of our Meetups around the world
  • Located in United Kingdom
+3 more
FlatKing
says

If the issue is that your loop content is being echoed on top of all page contents then wrap your loop code like this …
    ob_start(); 

    get_template_part( 'blog', 'index' );  // your loop here

    $return = ob_get_contents();
    ob_end_clean();
    return $return;

Hope it helps :)

Got it working – you beauty! I could kiss you!

by
by
by
by
by
by