[ad_1]
Hi, what do you mean by “might not be available”? It is a WP global variable:
$post (WP_Post) The post object for the current post. Object described in Class_Reference/WP_Post.
That shouldn’t have anything todo with ACF or not.
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: "]
No, sorry. Maybe it is getting the ID of the template page and not the content page. Check the files in the widgets/ folder of my plugin (e.g. the PostACF file) to see how I read the content of the pages.
But if you use custom code it is not part of this plugin so you have to solve that yourself. Hope you can figure it out.
