This shortcode returns the value of a specified key that is found in the current global $post object. This shortcode includes a key attribute where you specify which variable you want to output.
[CF7_get_post_var key="<insert variable key>"]
This shortcode also includes an optional post_id attribute where you can specify the post ID for a different post or page to pull a variable from it instead.
[CF7_get_post_var key="<insert variable key>" post_id="<insert post ID>"]
Note: this shortcode only works on WordPress pages that are of the WP_Post type. If you’re looking to create a form that goes into templated area like the footer and you want fields for titles and URLs to work for archive pages as well, please see CF7_get_current_var instead!
Example
If I wanted to get the title of the current post, the value of my dynamic field would use this:
CF7_get_post_var key='post_title'
And then the dynamic text form tag would look like this:
[dynamictext inputname "CF7_get_post_var key='post_title'"]
I could also choose to display the post title of a different post or page than the one currently being viewed by using the following dynamic form tag:
[dynamictext inputname "CF7_get_post_var key='post_title'" post_id="123"]
Possible Options
Any property that is available from global $post object (type: WP_Post) and returns a string or numeric value can be used such as:
- Post ID:
CF7_get_post_var key='ID' - Title:
CF7_get_post_var key='post_title' - Author:
CF7_get_post_var key='post_author' - Publish date:
CF7_get_post_var key='post_date' - Excerpt:
CF7_get_post_var key='post_excerpt'
Cache Compatibility
If cache compatibility mode is enabled for the form tag that uses this built-in shortcode, it does not make an AJAX request. Instead, it simply uses the preexisting value because the value retrieved by this shortcode is safe to cache.
Demo
Check out these fields in action! I’m pulling in various information about this post including the publish date, last modified date, and excerpt!
View Source Code
View the source code for the server-side shortcode or for the client-side JavaScript function.
hi,
how can i have a custom post type for example “calc-varosok” in English “City” all title.
I want a checkboxes with all city what I have in CPT.
citys = [‘Budapest’,’Paris’,];
Hello! This is absolutely possible with this plugin now. I have just finished updating the documentation on the dynamic checkboxes. I’m sure that can help you more than this page. Cheers!