Dynamic Shortcode Values
-
Hello,
I am trying to dynamically generate shortcode content based on user-input form fields. I have created the function where the shortcode names (i.e., [blah]) come from the custom fields of any given post. However, I can only generate the content for the shortcode if I type a specific string value in the function called by add_shortcode.
For instance:
function myFields() { $fieldValue = "Content for the shortcode." return $fieldValue; } foreach ( $custom_field_keys as $key => $keyName ) { //Bunch of other stuff add_shortcode((string)$keyName, 'myFields'); }
When [$keyName] exists in the post, it will be replaced by “Content for the shortcode” with no problems.
However, if I try and reference $fieldValue directly or even convert it into a string, [$keyName] has no value in the post:
$custom_field_keys = get_post_custom_keys(); function myFields() { return $fieldValue; } foreach ( $custom_field_keys as $key => $keyName ) { //Bunch of other stuff add_shortcode((string)$keyName, 'myFields'); }
I am thinking that it has something to do with calling the function from within foreach. For some reason the value for $fieldValue is not being retrieved.
Any help would be appreciated and I’ll answer any questsions! Thanks!
- The topic ‘Dynamic Shortcode Values’ is closed to new replies.