Skip Navigation

[Resolved] making a relationship with 3 variables

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.

Our next available supporter will start replying to tickets in about 1.42 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#2453631

Hi Waqar
This is looking great. However, I cannot get the content template for service pages to display the correct output. It looks like the content template is not interpreting the code as code, but instead it is displaying the code as text.

My custom fields are named differently from your dummy data; I couldn’t work out the syntax of the function. For example in the Location Field group, you defined 2 fields as

[Location Field 1] with slug [location-field-1] and [Location Field 2] with slug [location-field-2];

I defined:

[TownName] with slug [townname], and [county], with slug [county]

I tried to replace your slugs with mine but it still only displayed the code as text. Where am I going wrong?

Also I have defined a 3rd Custom Code snippet, can you check if that is correct?

Thank you

Saeed

#2453863

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad that we're making progress.

Here are some important points to note:

1. The "Code" block outputs the content/text as it is, without any processing, so it is not a good fit for showing the content that includes the shortcodes.

2. The "Fields and Text" block is a good fit, but it is important to switch to the "HTML" tab, before adding the content, because the "Visual" tab will also show the content as it is and will even add extra formatting tags.
( screenshot: hidden link )

3. Here are details to better understand the usage of those shortcodes:

These are the examples of the custom shortcode to get the ID of the current post's location, brand, and model term ID:


Location ID:
[get_terms_by_level level='location' return='id']

Brand ID:
[get_terms_by_level level='brand' return='id']

Model ID:
[get_terms_by_level level='model' return='id']

And here is a simple example of how the Types Fields API shortcode works to get the data from the taxonomy term's field:
( ref: https://toolset.com/documentation/customizing-sites-using-php/functions/ )

Where the slug "slug-of-field" field is the slug of our target term field and "123" is the ID of the target term from which we need to get the field data:


[types termmeta="slug-of-field" term_id="123"][/types]

And since we have registered the custom shortcode 'get_terms_by_level' to get our target taxonomy term's ID, we'll use that to pass the target term ID in that "types" shortcode's "term_id" attribute.

Combining the two shortcodes it becomes:


[types termmeta="townname" term_id="[get_terms_by_level level='location' return='id']"][/types]

4. And because we need to use our custom shortcode 'get_terms_by_level' as the attribute value of another shortcode (types), it is important that the system recognizes this custom shortcode.

Which is why it needs to be added in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
( I've added it now - screenshot: hidden link )

You can see that the example shortcodes are working on the service post pages now.

5. The third code snippet that you added looks good and I've added small adjustments to it.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.