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