Skip Navigation

[Resolved] Display problem with checkbox field

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

Problem:

The issue here is that the user wanted to display the parent field of a post.

Solution:

IF the field is not on the child post then you can do it by doing this.

[types field='product-labeled-gluten-free' id="[wpv-post-id item='@packaged-food-test-for-a-product.parent']"][/types]
This support ticket is created 5 years, 7 months 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by craigB-7 5 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1114842
checkbox-setup.png
content-template-display-checkbox.png
checkbox-checked-as-displayed-on-site.png
checkbox-unchecked-as-displayed-on-site.png

I am trying to display a checkbox field, with values of "Yes" if the checkbox is checked and "No" if it is not. When I set up the custom checkbox field, I specified that the value to show should be "Yes" if selected, and "No" if not selected.

I am attempting to display the field in a content template as a "Post Field", since that seems to be the only option that appears to actually give me the content of the checkbox field. The checkbox field in question is coming from the "one" side of a one-to-many relationship. The rest of the content in the template is coming from the "many" side. However, when I view the page, the output for the checkbox is 1 if checked, and it is blank if unchecked.

I am attaching screenshots of the custom checkbox field setup, as well as how I am referencing it in my content template. I am also attaching screenshots showing what is being output on the page for both checked and unchecked states.

What do I need to do to get this to display something other than 1 or nothing?

#1115131

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

Thank you for contacting our support forum.

This is happening because you are using the views shortcode to get the value. What you need to use is the Types shortcode to get the value and it will return the texts.

Example.
[types field='new'][/types]

You can also pass the same ID into the shortcode as well.

Thanks,
Shane

#1115159
types shortcode display options.png
types shortcode post selection.png
content template with types shortcode.png
types shortcode checkbox checked displayed on site.png
types shortcode checkbox unchecked displayed on site.png

Thank you for the response, Shane. I have actually tried that. In fact, that's what I initially attempted before using the "Post Field" method I sent you previously. If I change to using the types shortcode, I get a value of "No" regardless of whether the checkbox is checked or not. I think that this is due to the fact that when using the types shortcode, I'm unable to specify that the data should come from a post related to the current post. In other words, I think it's trying to pull the data from the current post, which is on the "many" side of the relationship. The desired field does not exist in the current post. Rather, the field needs to come from the "one" side of the relationship. But when I do the types shortcode, it does not give me the option to specify that the data should come from a related post. I'm attaching screenshots to hopefully illustrate the problem. Thanks!

#1115194

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

Would you mind allowing me to have access to the site so that I can take a look at this more closely?

The private fields have been enabled for your next response.

Thanks,
Shane

#1115210

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

Could you send me the link to the page where you've been testing this?

Thanks,
Shane

#1115219

Sorry, yes.

The following page should show "Labeled Gluten Free: Yes":

hidden link

The following page should show "Labeled Gluten Free: No":

hidden link

#1115740

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Craig,

I was able to get it to work by passing the id of the parent into the shortcode.

{!{types field='product-labeled-gluten-free' id="{!{wpv-post-id item='@packaged-food-test-for-a-product.parent'}!}"}!}{!{/types}!}

Please let me know if it helps.

Thanks,
Shane

#1115752

My issue is resolved now. Thank you!

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