Calling variables into functions.php
-
Hello,
I’m probably getting this all confused but is there any way to get a variable from outside of the functions.php file (say in single.php) and feed it into a function?I’ve got a function which adds a field to a custom form and I want to feed a variable into the value of an input. The form is placed at the bottom of a post and when submitted it creates a custom post type post that gets displayed at the bottom of the regular post in a list format. I want to get the ID of the parent post. This will then feed into the value of the hidden input of the custom post type form, then I can do a query to get all custom post types with the meta_value of this ID.
So I’ve got this:
function feed_the_form_hook($form_id, $post_id, $form_settings) { $value = ''; if ($post_id) { $value = get_post_meta($post_id, 'parent_post_id', true); } ?> <div class="wpuf-label"> <label>Hidden Chalet Review ID</label> </div> <div class="wpuf-fields"> <input type="text" name="parent_post_id" value="<?php echo esc_attr($parentPostID); ?>"> </div> <?php echo $parentPostID; //Delete this once tested output } add_action('parent_post_id', 'feed_the_form_hook', 10, 3);
The $parentPostID variable is getting the ID from the single.php file. I know this won’t work as is but is there any way of doing this or am I going about it in the wrong way?
I did post something similar a while back but was asked to post in the plugin forum. I didn’t get an answer from there but this is actually a different problem. I’m simply wondering if this is possible within WordPress, regardless of plugins used etc?
Thank you.
- The topic ‘Calling variables into functions.php’ is closed to new replies.