Get shortcode of form programmatically, using form’s ID
-
I’d like to use a contact form in a general template like
single.php, but I’d like to be able to configure which form is included in the template as a site option. The shortcode should not appear in thepost_content, it should be coded into the template.But instead of a hardcoded form value like
[contact-form-7 id="e07e78b" title="Inquire about this work"], I’d like to be able to configure which form appears.Using ACF, I can store a specific
contact_formas a siteoption. (contact_formis a post_type, so i can pick which form I want to store in the option, and access it elsewhere viaget_field.)I’m trying to understand if there’s a way to use that form’s ID to get the generated shortcode for that form. I notice that the form shortcode
iddoes not correspond to the form’spost_idin the database, and I can’t find where it’s stored in thepost_metaof the form, either.I do find that there’s a method of
WPCF7_ContactFormcalledshortcode()that generates the shortcode. I’m wondering how I can pass the form$postobject and get the generated shortcode for it, in a template.
The topic ‘Get shortcode of form programmatically, using form’s ID’ is closed to new replies.