I am creating a function, for a shortcode that I will use directly in the post content (using [my_description_number]
shortcode), and it works, but I do not manage to call (echo or print) a custom field value.
this will not print the custom field value, maybe you know how to make it work? just to print the value of custom field song_number
when the shortcode will be called
many thanks
function wpb_description_shortcode( $atts ) : string {
ob_start();
?>
<?php if (get_post_meta(get_the_ID(), 'song_number', true)) { ?>
<?php echo get_post_meta($post->ID, 'song_number', true); ?><br/>
<?php } else { ?> <?php } ?>
<?php
return ob_get_clean();
}
// Register shortcode
add_shortcode('my_description_number', 'wpb_description_shortcode');```