Dynamic Content with Shortcode working only partially

So I created a shortcode [latestsermonid] using wordpress’ guide.
It’s super simple, and basically gets the postid for the latest post in category “sermon”
The shortcode works great for text stuff, but as soon as I’m trying to use it in anything link related ( a href ) tags, it starts to glitch out.

Sample code: (the output of the text works great, but the “href” dynamic content gives the url of the page its on, not the permalink)

<div>
 <a href="{{dc:post:permalink post="[latestsermonid]"}}">
  {{dc:post:title post="[latestsermonid]"}}
 </a>
</div>

This is the shortcode in functions.php -

// shortcode: latest post ID for sermons
function LatestSermonID() {

	$args = array(
		'numberposts' => 1,
		'offset' => 0,
		'category' => 400,
		'orderby' => 'post_date',
		'order' => 'DESC',
		'include' => '',
		'exclude' => '',
		'meta_key' => '',
		'meta_value' =>'',
		'post_type' => 'post',
		'post_status' => 'publish',
		'suppress_filters' => true
	);

	$recent_posts = wp_get_recent_posts( $args, ARRAY_A );
	$thePostID = $recent_posts[0]['ID'];

		return $thePostID;
	}
add_shortcode('latestsermonid', 'LatestSermonID');

Hello Jon,

Thank you for the very detailed post information.

You just cannot nest shortcodes within double quotes. You can either escape the quotes or use singles.
Please have your shortcode updated and use this:

<div>
 <a href="{{dc:post:permalink post=\"[latestsermonid]\"}}">
  {{dc:post:title post="[latestsermonid]"}}
 </a>
</div>

Kindly let us know if this works out for you.

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