481 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
  • Has referred 1+ members
  • 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 :)

481 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?

481 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!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by