Skip Navigation

[Resolved] Add shortcode in

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 4 years ago.

Assisted by: Minesh.

Author
Posts
#1891523

Hello,

I would like to add the shortcodes in the title tag of the site. For that I use yoast seo.

For simple shortcodes this works, but for a parent relationship it doesn't.

For example for the shotcode: [types field = 'nom-ville'] [/ types]
The correspondence with yoastseo is: %%cf_wpcf-nom-ville%%
It works well ! Good

But for this shortcode with parrent I can't get it to work.
Example shortcode: [types field = 'cp2-departement' item = '@ departement-ville.parent'] [/ types]
What is the structure to do for yoastseo so that it appears in the title ???

Yoast told me to ask you because it should work the same.

Thank you

#1892031

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

AS per the Yost's Doc, for such fields, you will require to create your own custom field placeholder and assign the value of that variable.
=> hidden link

Here they shared the example:
=> hidden link

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/

#1892667

Hello,

Thank you for your reply. I understand for a hard variable. But how to do the php code to retrieve a value from the parent automatically based on the page?

#1893587

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Toolset offers post relationship API function: toolset_get_related_post
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

Using which you can get the parent ID of current child post.

For example;

global $post;
$parent_id  = toolset_get_related_post( $post->ID, 'post-relationship-slug');

// getting custom field value that belongs to parent post
$field_value = get_post_meta($parent_id,'wpcf-cp2-departement',true);

Where:
- You should replace "post-relationship-slug" with your original post relationship slug

I hope above solution clarify how you can get parent ID and get the parent custom field value.