Do you have any idea why the metadata isn't appearing on the custom post details template?
function display_custom_post_meta_shortcode( $atts ) {
? ? // Extract shortcode attributes
? ? $atts = shortcode_atts( array(
? ? ? ? 'post_id' => get_the_ID(), // Default to current post ID if not specified
? ? ? ? 'meta_key' => '', // Specify the meta key
? ? ? ? 'before' => '', // Text to display before the meta value
? ? ? ? 'after' => '', // Text to display after the meta value
? ? ), $atts );
? ? // Check if the meta key is specified
? ? if ( empty( $atts['meta_key'] ) ) {
? ? ? ? return ''; // Return empty string if meta key is not specified
? ? }
? ? // Get the meta value for the specified meta key
? ? $meta_value = get_post_meta( $atts['post_id'], $atts['meta_key'], true );
? ? // Output the meta value with before and after text
? ? if ( $meta_value ) {
? ? ? ? return $atts['before'] . $meta_value . $atts['after'];
? ? } else {
? ? ? ? return ''; // Return empty string if meta value is not found
? ? }
}
add_shortcode( 'custom_post_meta', 'display_custom_post_meta_shortcode' );
// [custom_post_meta meta_key="project_date" before="Meta Value: "]