Problem: I have two custom post types in my site. They are not related using Toolset Post Relationships, but they are related using a post ID field. Custom Post Type A (CPT A) contains a custom date field. Custom Post Type B (CPT B) contains a custom number field that stores the numeric ID of some post from CPT A. In the template for CPT B, I would like to display the date field from the post in CPT A with the ID stored in CPT B's numeric field. The following solution works well technically, but uses a hard-coded post ID:
[types field='person-date-of-birth' item='26'][/types]
The date of birth stored in post ID 26 is displayed correctly, but it's not practical for me to use a hard-coded post ID. So I tried using a nested shortcode in the "item" attribute of the outer shortcode, but it is not working correctly:
[types field='schema-person-monastic-name' item='[types field='schema-person-honorific-prefix'][/types]'][/types]
Solution: Any time you nest Types field shortcodes like this, you should use the raw output attribute in the inner nested shortcode. This way no extra spaces, line breaks, or HTML formatting are included in the output, which would break the outer shortcode. It is also recommended to alternate between single and double quotes per nesting level, like this:
[types field="schema-person-monastic-name" item="[types field='schema-person-honorific-prefix' output='raw'][/types]"][/types]
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/#numeric
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 7 replies, has 2 voices.
Last updated by 4 years, 11 months ago.
Assisted by: Christian Cox.