Tagged: shortcode
Custom User Metadata shortcode does not work on tabs but works on pages just fine.
Hi Mike,
Welcome to BuddyDev support forums.Please share the exact shortcode you are using.
Thank you
BrajeshHello Mike,
The current implementation of the shortcode is problematic because BuddyPress pages reset the $post variable, rendering it unavailable. To address this issue, it is recommended to modify the shortcode to accept additional attributes, allowing the manual specification of the post ID. However, this approach results in a static configuration, limiting the shortcode’s flexibility with respect to dynamic post IDs.
Regards
RaviSo what is your recommendation?
function my_assessment_score($atts) {
// Parse the shortcode attributes
$atts = shortcode_atts(array(
‘post_id’ => null, // Default to null if no post ID is provided
), $atts, ‘assessment_score’);// Determine the post ID to use
$post_id = $atts[‘post_id’] ? intval($atts[‘post_id’]) : get_the_ID();// Return the assessment score for the specified post ID
return get_post_meta($post_id, ‘assessment_score’, true);
}
add_shortcode(‘assessment_score’, ‘my_assessment_score’);this still didn’t work
Hi Mike,
You will meed something like thisfunction my_assessment_score( $atts ) { // Parse the shortcode attributes $atts = shortcode_atts( array( 'post_id' => 0, // Default to 0 if no post ID is provided ), $atts, 'assessment_score' ); // Determine the post ID to use $post_id = $atts['post_id'] ? intval( $atts['post_id'] ) : get_the_ID(); // Return the assessment score for the specified post ID return $post_id ? get_post_meta( $post_id, 'assessment_score', true ) : ''; } add_shortcode( 'assessment_score', 'my_assessment_score' );
Also, for the profile tabs, if you do not pass the post id, It will not show anything.
Regards
Brajesh
You must be logged in to reply to this topic.