Yes, you can retrieve the saved meta value and pass it as a parameter to a shortcode.
First option is to get the saved value to a variable, validate it and then concatenate it to a shortcode string you pass to do_shortcode()
.
// get saved meta value
$form_id = get_field('your_key_for_form_id_here');
// make sure we have an ID and it is a number, string or int
if ( $form_id && is_numeric( $form_id ) ) {
// do_shortcode returns the shortcode html, so you need to echo it yourself
echo do_shortcode('[gravitywp_count formid=' . $form_id . ']');
}
Another option is to just concatenate the meta directly to the shortcode string, if you trust the saved meta value will always be in the right format.
echo do_shortcode('[gravitywp_count formid=' . get_field('your_key_for_form_id_here') . ']');
You can also skip the shortcode part and just call your callback function directly in your template file.
// modify your callback to take form id directly as a parameter
function your_entries_counting_function( int $form_id ) {
// your code to get the entries count
}
// get meta data
$form_id = get_field('your_key_for_form_id_here');
// make sure it is what you're expecting
if ( $form_id && is_numeric( $form_id ) ) {
// pass the ID to your function
echo your_entries_counting_function( intval( $form_id ) );
}
If you’re only using ACF for adding the form ID meta field, you could simplify your setup by just registering the metabox yourself with add_meta_box()
and leaving ACF out of the picture altogether. In this case you would then use get_post_meta()
to retrieve the saved form id meta value,
$form_id = get_post_meta( get_the_id(), 'your_key_for_form_id_here', true );