Hi @uaoh , I’d be happy to help!
You can manually set the post ID in the built-in shortcode using the post_id attribute if you need to pull from a specific one like this:
[dynamichidden page-title "CF7_get_post_var key='title' post_id='123'"]
When a post ID is not provided (as is the case for most users), it tries to perform the lookup from the global $post object, and if that fails, then it uses get_the_ID() from the “the loop”
But I’m guessing this contact form is inserted in a template that appears both on single.php and archive.php, so not ideal to create multiple forms for those instances. I’ll see what I can do 🙂
Thread Starter
uaoh
(@uaoh)
Hi, thanks for answering.
Yes, the contact form is inserted in a template. In this case (a custom template). Please keep me updated.
Mauro
So I know what the problem is and what the answer is, it’s just a matter of figuring out the best implementation method 🙂
Problem: the shortcode is trying to get a post variable from an archive page
Solution: use a shortcode that can automatically determine if the current page is a post or archive and then use the appropriate function to retrieve the title
I’m currently writing a new built-in shortcode called CF7_get_current_var to do just that, so bear with me! When it’s done, you’ll be able to use this in the form builder:
[dynamichidden page-title "CF7_get_current_var key='title'"]
This shortcode was added in version 3.4.0. Let me know how it works for you!
Thread Starter
uaoh
(@uaoh)
I tried on a copy of the page and it works! Thank you very much