[Resolved] Types Shortcode is not displaying value – possible custom code problem
This support ticket is created 5 years, 1 month 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.
I have custom code which sets a select field for a new Grant Application post. The code is shown below. This is working as I can see the value is set in the database.
The problem comes when I try and display the grant-year-select field, which has the title "Grant Year", using the types shortcode. It is only displaying the value if the value matches the sc-grantyear. So if the sc-grantyear is set to "2019" then the following will only display a value if the value is 2019.
[types field='grant-year-select'][/types]
If I disable the function sc_populate_grantyear and then view existing posts the shortcode will display the grant-year-select correctly. So this is showing me the value is saved to the post correctly. But for some reason my function is preventing the value from being displayed unless it matches sc-grantyear.
Thank you for contacting us and I'll be happy to assist.
The code that you've shared, bypasses any options that you've set in "Grant Year" select field's settings and any values that may be saved in the field previously. It will only show what is saved in "sc-grantyear" option.
This means that whenever you'll be adding or editing the post from the admin area or through the front end form, the "Grant Year" field will only show one select option, based on the year value set in the "sc-grantyear" option.
If you could share some more details around what you're planning to achieve, I'll be in a better position to guide you accordingly.
Yes, that is what we want. The grant year select field is hidden and set automatically using this code based on another variable. Each year applicants can apply for a grant. We set the grant year according to the funding year. So the post type Grant Applications has a number of posts each reflecting the grant year in which they were submitted for a grant.
Where I'm having a problem is displaying the value of that field on the front end using Types. Regardless of what the stored value is in the grant year select field the types shortcode is returning the value of the sc-grantyear variable. I can't figure out why. When I look at the database I see the correct value in the grant year select field. Is there additional information I can provide you to help with this issue?
The value that is returned through the "[types field='grant-year-select'][/types]" shortcode is filtered through the function attached to "wpt_field_options".
Thank you for helping to solve the mystery. I had not expected the Types shortcode to filter through wpt_field_options. Using [wpv-post-field name="wpcf-grant-year-select"] worked perfectly. Thanks for your assistance.
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.