This shortcode returns a comma separated list of values of a specified taxonomy assigned to the current (or otherwise specified) post or page.
By default, it pulls a comma separated list of names of all WordPress categories assigned.
[CF7_get_taxonomy]
This shortcode includes an optional taxonomy attribute where you can specify a different taxonomy, such as tags or a custom one, using its slug as the value.
[CF7_get_taxonomy taxonomy="<taxonomy slug>"]
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_taxonomy taxonomy="<taxonomy slug>" post_id="<insert post ID>"]
This shortcode also includes an optional fields attribute where you can specify a different field list instead. Options include names for a list of taxonomy names, slugs, for a list of taxonomy slugs, or ids, for a list of taxonomy IDs. The default is names.
[CF7_get_taxonomy taxonomy="<taxonomy slug>" post_id="<insert post ID>" fields="<insert field type>"]
Examples
If I wanted to a comma separated list of category names assigned to the current post, the value of my dynamic field would use this:
CF7_get_taxonomy
And then the dynamic text form tag would look like this:
[dynamictext categories "CF7_get_taxonomy"]
I could also choose to display the categories of a different post or page than the one currently being viewed by using the following dynamic form tag:
[dynamictext categories "CF7_get_taxonomy post_id='123'"]
I could also choose to display the category IDs instead of the category names by using the following dynamic form tag:
[dynamictext categories "CF7_get_taxonomy fields='ids'"]
I could also choose to display a list from a custom taxonomy, such as product categories (product_cat) if using WooCommerce, by using the following dynamic form tag:
[dynamictext product_categories "CF7_get_taxonomy taxonomy='product_cat'"]
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 it out! In the demo form below, I’m using this shortcode to reference the categories and posts assigned to this article.
View Source Code
This shortcode was added to the Contact Form 7 – Dynamic Text Extension WordPress plugin in version 3.3.0. View the source code for this shortcode included with DTX.
Hi, where can I find the 4.0.0 version? In WordPress there’s only the 3.2 version.
Thanks!
Hi Claudio,
The 4.0.0 mentioned here is a beta version and you can download it from my github repo here: https://github.com/Tessachu/contact-form-7-dynamic-text-extension
Cheers!
Hi,
I tested with version 3 and version 4 next examples:
1.
[dynamictext product_categories "CF7_get_taxonomy taxonomy='product_cat'"]2.
[dynamictext procat "[cf7drop-product-categories]"]Where shordcode
cf7drop-product-categories– returns only names of product categories.But no success. In First (Your) example – form display blank dropdown field.
In second, with shortcode it displays part of shortcode followed by categories names, like this:
Can You help me please?
I’d love to help 🙂
First, I’d like to make sure I understand your intent. This shortcode is used for pulling taxonomies assigned to a post object and when no post ID is provided, it looks to the current post. This is also a text input field, not a select or dropdown field.
One reason that your text field is empty is that the post (assuming to be a WooCommerce product based on your code snippet) does not have any product categories assigned. Please double check that (especially since I too sometimes assign post categories to products instead of product categories to products, make sure your categories were created using the correct taxonomy!).
If you do have product categories assigned to your product, your code snippet marked as 1 should provide you that comma separated list of category names.
As for your second snippet, you need to omit the brackets to use custom shortcodes, like this:
Hope that helps! Cheers!