Skip Navigation

[Resolved] Select Type Custom field not displaying

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

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

Last updated by Shane 6 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#915430

Amr
Screen Shot 2018-06-19 at 10.58.04 AM.png
Screen Shot 2018-06-19 at 9.09.45 AM.png

We have a "Select" type custom field called "Self Assessment 1 Quiz" that does not have any default option specified. We dynamically populate the available options for this field in a CRED form using the following function that queries a separate table to find the available options:

add_filter( 'wpt_field_options', 'selectfieldoptions', 10, 3);
function selectfieldoptions( $options, $title, $type ){
switch( $title ){
case 'Self Assessment 1 Quiz':
global $wpdb;
$options = array();
$myrows = $wpdb->get_results( "SELECT id, name FROM DB_selectOptions where (cat_id = '1') or (name='-') ORDER BY name" );

foreach ($myrows as $post) {
$options[] = array(
'#value' => $post->id,
'#title' => $post->name,
);
}
break;
}
return $options;
}

This solution works well and the correct values do get stored in the custom "Self Assessment 1 Quiz". However, when we try to display/output that field in a content template using [types field='self-assessment-1-quiz' output='raw'][/types], the output is blank. Interestingly, using [wpv-conditional if="( $(wpcf-self-assessment-1-quiz) ne '' )"] does work and does detect that the value stored in the field is not empty indicating that there is a value stored but it cannot be displayed.

However, If we change the field definition and explicitly add options, then the field does display when using [types field='self-assessment-1-quiz' output='raw'][/types].

This behaviors started happening when we updated to the latest version of Types(3.0.1) and Views(2.6). Prior to these versions, we were able to display the value of "Select" fields even if the options are not defined.

Please see attached screenshots of the field definition without options and with options.

#915497

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for contacting our support forum.

Could you try using this shortcode an let me know if the field starts displaying ?

[wpv-post-field name='wpcf-self-assessment-1-quiz']

Thanks,
Shane

#915502

Amr

Hello Shane,

Yes, [wpv-post-field name='wpcf-self-assessment-1-quiz'] does work.

Does that mean we have to replace every occurrence [types field='self-assessment-1-quiz' output='raw'][/types] with [wpv-post-field name='wpcf-self-assessment-1-quiz'] in our solution as well as in any other solution we have developed where we use "Select" type custom field that have no options defined .?

Thanks

#915884

Shane
Supporter

Languages: English (English )

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

Hello,

No you shouldn't need to .

Could you try without the RAW attribute and let me know if it works then.

Thanks,
Shane

#915895

Amr

Hello Shane,

Removing the raw attribute does not make a difference. I have already tried it.

#916025

Shane
Supporter

Languages: English (English )

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

Hello,

I'm not sure why this field is not showing up as the Types shortcode should work. Does this only occurs for this custom field only?

However the [wpv-post-field name='wpcf-self-assessment-1-quiz'] will work just as well.

Thanks,
Shane

#916058

Amr

Hi Shane,

As I said in my post, this happens only with Custom fields that have the Type "Select" and the Option not set.

Any other type of custom field works just fine with [types field='filename'][/types]

Please try it on your WordPress installation. Create a Custom filed of type "Select" and do not set the option. Then populate the custom field with a value using a CRED form. Now when you try to display the value of that field using [types field='filename'][/types] you will see that it is blank. Only [wpv-post-field name='filename'] works.

In the past with prior version of Types and Views, it used to work both way.

#916254

Shane
Supporter

Languages: English (English )

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

Hi Amr,

I understand now but what would the [wpv-post-field ] shortcode display if the field has no options. I would expect it to be blank.

I can see why the Types shortcode doesn't return a value.

Thanks,
Shane

#916283

Amr

Hi Shane,

As I explained it in my post, we populate "Select" custom field using a CRED form and supplying the pulldown option with values that are stored in a separate table and brought over using a custom function/filter.

add_filter( 'wpt_field_options', 'selectfieldoptions', 10, 3);
function selectfieldoptions( $options, $title, $type ){
switch( $title ){
case 'Self Assessment 1 Quiz':
global $wpdb;
$options = array();
$myrows = $wpdb->get_results( "SELECT id, name FROM DB_selectOptions where (cat_id = '1') or (name='-') ORDER BY name" );

foreach ($myrows as $post) {
$options[] = array(
'#value' => $post->id,
'#title' => $post->name,
);
}
break;
}
return $options;
}

So we are able to store values in the Select custom field but cannot display them using [types field='filename'][/types]

#916322

Shane
Supporter

Languages: English (English )

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

Hi Amr,

Yes I re-read the issue now.

In this case I would recommend keep using the [wpv-post-field] shortcode.

Thanks,
Shane

#916418

Amr

Hi Shane,

We will use [wpv-post-field] for new solutions, but how about existing solutions. We have several sites where we use [types field='filename'][/types] across the board since this shortcode used to work. Now all these sites where Select custom fields are used are in effect broken.

Where you able to recreate that problem on your end ?

Please escalate this issue in order to create a fix.

Thanks

#916728

Shane
Supporter

Languages: English (English )

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

Hi Amr,

I'm actually aware of this issue. I believe Types shortcode needs some reference in order to retrieve the field information. Each field type is handled different by our shortcode even though we use the same shortcode.

The wpv-post-field shortcode can get the raw data from the database. So this is why I believe that the Types shortcode is processing this differently .

I'm not privy to the intricate workings of this but I suspect this is the issue based on looking at why the [wpv-post-field] works. If you were to add some values to the select I know it would work.

I don't think this is something that our development team would fix either because of the use of an undocumented hook.

Thanks,
Shane

#916756

Amr

Hi Shane.

The fact that "Select" custom fields with no options used to work in the past with the shortcode [types field='filename'][/types] and many solutions were built based on them and now they stopped working, is problematic. There is no mention anywhere that the shortcode [types field='filename'][/types] is deprecated and should not be used with "Select" custom fields.

Why then would you allow "Select" custom fields with no options to be defined. The system should detect that condition and warn you.

We now have to revise all our solutions to adjust to that change. The is unfortunate.

Amr

#916782

Shane
Supporter

Languages: English (English )

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

Hello,

This is something that I can report. It use to work and now it doesn't I can mention this in the escalated ticket that i'm creating.

I made the report and currently awaiting a response from them.

Thanks,
Shane