Display the content of the latest post in a page with a shortcode

Hey there,

I’m trying to create a shortcode to display the content of the latest post in a page. When I write the post with the classic WP editor ie plain text/html all is well, but when the post is created with the pro builder I get {{base64content “” }} in my page.

I’m using the latest version of pro and my custom code is:

function latest_post_content_shortcode_handler( $atts, $content = null ) {
	
	$args = array( 'posts_per_page' => 1 );
	$custom_query = new WP_Query( $args );
	if ( $custom_query->have_posts() ) : 
		while ( $custom_query->have_posts() ) : $custom_query->the_post();
			$output = get_the_content();
			// $output = the_content();
			// $output = x_get_view( 'global', '_content' );
			return $output;
		endwhile;
	endif;			
	wp_reset_postdata();
	
}
	add_shortcode('latest_post_content', 'latest_post_content_shortcode_handler');

As you can see I tried the_content(); instead of get_the_content(); & also x_get_view( ‘global’, ‘_content’ );

Why doesn’t the cornerstone content get rendered before output?

Richard

Hey Richard,

Thanks for writing in! Your code maybe invalid. Regretfully this is custom development and way beyond the scope of our support. I would recommend that you consult a developer or change your code based from these references.
https://web-design-weekly.com/snippets/recent-post-shortcode/

Or you just install 3rd party plugins if you are not very familiar with coding. Perhaps these plugins would help:
https://wordpress.org/plugins/search/latest+post/

Hope this helps.

RueNel,

I don’t think my code is invalid. If I write a post in the wp editor, ie non cornerstone, all is well. The problem lies in the fact that I’m using cornerstone to create posts. Note that I need the content of a post to be rendered on a page, not links to latest posts. Those work fine as well as other metadata for posts.

You say that this is beyond the scope of support, but it seems to me that in numerious occasions there is a lot of inconsistancy in deciding what is and what is not beyond the scope of support.

If tried a couple of plugins , but the same problem arises. My guess is that there must be a trick to output cornerstone content via a shortcode.

Richard

Hi Richard,

Content created using content builder/Cornerstone is wrap by a lot of html tags. This is the reason why either the plugins that use convert post into a shortcode or above code is not working. We do help in simple customization but complex functions is outside the scope of support. We do have an in-house custom development team that offer paid services, who may be able to assist. They can be contacted at pinnacle@theme.co if this is of interest to you. If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.

Thank you for your understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.