I'm trying to create a plugin that display the specific post content by using POST ID.
example:
[post id="2"]
But I don't know how to send POST ID from function to $my_postid below are my code
function post_function($atts) {
extract(shortcode_atts(array(
'id' => 21504,
), $atts));
//getting post content
$my_postid = 21504;//This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
return $content;
}
add_shortcode('post', 'post_function');`
extract()
works, you should be able to use it via$id
(because that is the key of the array). However, this is usually not recommended. The official docu uses an array as return element, and then access it via that array