Skip Navigation

[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.

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)

This topic contains 4 replies, has 2 voices.

Last updated by MaureenR3428 5 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1208685

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.

add_filter( 'wpt_field_options', 'sc_populate_grantyear_field', 10, 2 );
 
function sc_populate_grantyear_field( $current_options, $title_of_field ){
    
    if ('Grant Year' == $title_of_field ) {
        $selectYear = get_option('sc-grantyear');
        $current_options = array();
        $current_options[] = array(
                '#title'    =>  $selectYear,
                '#value'    =>  $selectYear
                );
    } 

    return $current_options;
}

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.

#1209403

Waqar
Supporter

Languages: English (English )

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

Hi Maureen,

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.

regards,
Waqar

#1209476

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?

#1209799

Waqar
Supporter

Languages: English (English )

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

Hi Maureen,

The value that is returned through the "[types field='grant-year-select'][/types]" shortcode is filtered through the function attached to "wpt_field_options".

But, if you'll use View's "[wpv-post-field name="wpcf-grant-year-select"]" shortcode, it will return what is saved in the database, as it is.
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field )

I hope this helps!

regards,
Waqar

#1210028

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.