Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1391969
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionThe situation is the following. I have got a shortcode from gravity forms that read the total entries that a form has recorded. For instance Form 1 - total entries 30. So the shortcode read that data and print out the value of 30.
As the shortcode must be updating for each form created by replacing ID's form I would like to pass a parameter to that shortcode for update that one from advanced custom field post.
the shortcode looks something like this
[gravitywp_count formid='']
where i must set the form id inside the '',
well , my idea is to have a custom field where the post creator set the number id of the new form created in gravity form and pass it to the shortcode through the custom field
It would be understood as
custom field:
Form ID: ID Value
then, the value that is posted there, pass to the shortcode once post is updated
[gravitywp_count formid='$thefield(form_id)']
logically, the shortcode will be placed into a file like single-customposttype.php
So i would like if this approach can be achieved or if there a better way to do this
Thanks to all of you for the help that you can bring me on this. Kind Regards
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionThe situation is the following. I have got a shortcode from gravity forms that read the total entries that a form has recorded. For instance Form 1 - total entries 30. So the shortcode read that data and print out the value of 30.
As the shortcode must be updating for each form created by replacing ID's form I would like to pass a parameter to that shortcode for update that one from advanced custom field post.
the shortcode looks something like this
[gravitywp_count formid='']
where i must set the form id inside the '',
well , my idea is to have a custom field where the post creator set the number id of the new form created in gravity form and pass it to the shortcode through the custom field
It would be understood as
custom field:
Form ID: ID Value
then, the value that is posted there, pass to the shortcode once post is updated
[gravitywp_count formid='$thefield(form_id)']
logically, the shortcode will be placed into a file like single-customposttype.php
So i would like if this approach can be achieved or if there a better way to do this
Thanks to all of you for the help that you can bring me on this. Kind Regards
Share Improve this question asked Feb 7, 2020 at 17:23 José DanielJosé Daniel 32 bronze badges1 Answer
Reset to default 0Yes, 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 );
本文标签:
版权声明:本文标题:How would i insert a value of custom field from Advaced Custom Field into shortcode generated by Gravity Forms 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744768209a2624173.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论