Pass shortcode variables to template

What I want to achieve

I have a custom page template, and I’d like to display some selected Posts on that Page. I’m developing this feature with shortcode. For now, I only need to receive the post ids in the page template.

What I have tried

In functions.php:

function post_link_shortcode($atts) {
$atts = shortcode_atts(
array(
‘id’ => ”,
),
$atts,
‘featured_posts’
);
}
add_shortcode(‘featured_posts’, ‘post_link_shortcode’);

In the admin panel page editor I have added:

Here are the featured posts:
[featured_posts id=”358,328″]

In the page template:

the_content();
echo do_shortcode(“[featured_posts]”);

What I expect

It outputs the IDs: 358,328 on the page along with the normal content. But It doesn’t. Any idea?

Read more here:: Pass shortcode variables to template

Leave a Reply

Your email address will not be published. Required fields are marked *