Skip Navigation

[Resolved] Nested Types fields are causing unwanted output

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a checkboxes group custom field and I would like to display a different field if one of the checkboxes is checked. I tried nesting one Types field shortcode inside another one, but it produces inaccurate results.

Solution:
Use conditional HTML to test that checkboxes field group's selected values against a known array:

[wpv-conditional if="(CONTAINS(ARRAY([types field='pdb-areas' output='raw'][/types]),'some-value'))"]
 <tr>
        <td width="321"><strong><em>Markedsføring:</em> [types field="company-name-short"][/types]'s Facebook side</strong></td>
        <td width="321">[types field="company-name-short"][/types] har oprettet en side på Facebook for markedsføring og for skabe et online fælleskab omkring [types field="company-name-short"][/types].</td>
      </tr>
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/cred-conditional-display-engine/

This support ticket is created 5 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 4 replies, has 2 voices.

Last updated by KenG8581 5 years ago.

Assisted by: Christian Cox.

Author
Posts
#1366657

I am using the Types field shortcode to check if a checkbox field is checked and then in that context, I am using Types fields shortcode nested to output the value of another field.

See example here:

[types field='pdb-areas' option='1' state='checked']
      <tr>
        <td width="321"><strong><em>Markedsføring:</em> [types field="company-name-short"][/types]'s Facebook side</strong></td>
        <td width="321">[types field="company-name-short"][/types] har oprettet en side på Facebook for markedsføring og for skabe et online fælleskab omkring [types field="company-name-short"][/types].</td>
      </tr>
      [/types]

However, this is causing an unwanted output - with [/types] being outputted and the actually the second [td] is outputted despite that the option 1 is not checked.

Is this due to nesting shortcodes not supported? Or something else?

How can I work around or fix this?

#1366789

I don't think you can use one Types field inside another like that, but depending on the values of the checkbox fields, you might be able to use conditional HTML with the array contains syntax like this:

[wpv-conditional if="(CONTAINS(ARRAY([types field='pdb-areas' output='raw'][/types]),'some-value'))"]
 <tr>
        <td width="321"><strong><em>Markedsføring:</em> [types field="company-name-short"][/types]'s Facebook side</strong></td>
        <td width="321">[types field="company-name-short"][/types] har oprettet en side på Facebook for markedsføring og for skabe et online fælleskab omkring [types field="company-name-short"][/types].</td>
      </tr>
[/wpv-conditional]

You would replace some-value with the checkbox field value you want to test. Obviously this only works if the checkboxes save different values.

#1366841

Thanks, Christian, I will try that out.

I did want to use wpv-conditional, but answer found in the support database says that it can't be done and recommends the Types fields approach.

The suggested approach may actually open up for some other advantages for my use.

Hang on - I will test and let you know the outcome.

#1366865

I'll stand by for your update.

#1370371

wpv-conditional is a better approach and adds additional capabilities.

My issue is resolved now. Thank you!