Skip Navigation

[Resolved] Field values set via a generic field not showing in View

This support ticket is created 2 years, 6 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 9 replies, has 2 voices.

Last updated by Simon Logan 2 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#2182791

Tell us what you are trying to do?
We have a form for users to complete which includes a select list which in turn displays a subset of users from the site. We are using a view to create the JSON data and a generic CRED field to use that data to create the list, we also have the PERSIST value set so that the data is stored to the db. This all works in that we can see the list and select a value and this value seems to be stored (as when we next edit the record the correct value is still there) however when I add this field to a View no value is showing up.

Is there any documentation that you are following?
https://toolset.com/forums/topic/create-a-select-user-drop-down-menu-field-to-link-one-custom-post-to-one-user/#post-326720

I'm using similar shortcode in the view to that which all other fields are output using, and I've tried every variant I think is available to me:
[types field="case-lender"][/types
][types field='case-lender' output='raw']
[/types][types field='case-lender' format='FIELD_NAME'][/types]
[types field='case-lender' format='FIELD_VALUE'][/types]
but no value is displayed using any of these shortcodes.

Any ideas?

#2182899

Shane
Supporter

Languages: English (English )

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

Hi Simon,

Thank you for getting in touch.

Is your generic field populating a custom field that was created in Types? Or are you creating a new custom field from the generic field.

Please let me know and we can take it from there. Ideally you can provide screenshots of the backend field and the forms the generic field as well.

Thanks,
Shane

#2182929
2021-09-29_15-32-06.png
2021-09-29_15-33-32.png
2021-09-29_15-32-33.png

Hi Shane

Nice to hear from you.

Yeah the custom field was creating using Types via Toolset>Custom Fields>Group Name then added here and its slug is "case-lender". So I believe we had to use a generic field in order to be able to display the list of users in a select list, however this field's value should be stored in that custom field.

I've attached some screenshots for you as follows: the custom field details created from within the Field Group using Toolset; the layout code used to generate the select list which in turn uses the view called "raw-lender-list" to display the list of users, to store it in the db and touse the field called "case-lender" to do so; then the view which is meant to display this value but which is where the problem lies - no value is output.

I even checked in the database and confirmed that values are being stored correctly in the meta table - so it looks like the values are being stored just fine but not output for some reason.

As an FYI is this the best approach to having a field which is basically there to list users for selection and store their ID? I see we can create a field which is of type "post reference" but not one of type "user reference" or equivalent.

#2182959
2021-09-29_15-32-06.png
2021-09-29_15-33-32.png
2021-09-29_15-32-33.png

Hi Shane, nice to hear from you.

Yeah the field was created using Toolset and the idea is that this field will store the value for a given user on the site. The generic field is there to display a select list which uses the JSON-formatted values from another view called "raw-lender-list" to populate it but its value should be stored in that custom field "case-lender".

This is what seems to happen properly however on the View which should display this value nothing is output even though the values seem to be getting stored just fine.

FYI is this the best approach to having a field whose value is effectively a reference to a user on the site? The value being stored is their ID so what we'd want/need is for the *name* of the person to be displayed (though I'm wondering if this could be achieved by outputting a user field then using the value for the "case-lender" field as the ID for the user we wish to display rather than the default "current user in the loop"). If there's a better approach, I'm open to it.

#2182989

Shane
Supporter

Languages: English (English )

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

Hi SImon,

Given that you're using a generic field to populate a types field you will need to use the wpcf- prefix for the field attribute. Change case-lender on your generic field to "wpcf-case-lender".

This should allow the generic field to insert the value into the types field that you've created.

Thanks,
Shane

#2182993

Apologies for the duplicate replies, I'd replied originally but then so no sign of it when the page reloaded so thought it had been lost and re-typed it all. Just about did it a third time!

Anyway, thanks for clarifying. So it looks like for whatever reason, in some circumstances I need to use that prefix but not in others? As the EDIT CASE form was able to pull that value out successfully and the db was storing it too. I presume this means there will be two meta values now in the db, one for the meta key "case-lender" and the other for the key "wpcf-case-lender" with only the latter being needed?

I can now see the values properly in my view - should my approach of adding a user field but swapping in the shortcode for the case lender field's value (ie the ID of the user selected in that dropdown list) rather than allowing it to use the default "current user in loop" value work?

#2183003

Shane
Supporter

Languages: English (English )

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

Hi Simon,

As the EDIT CASE form was able to pull that value out successfully and the db was storing it too. I presume this means there will be two meta values now in the db, one for the meta key "case-lender" and the other for the key "wpcf-case-lender" with only the latter being needed?

That is correct because your original meta key was case-lender so when the field is being created its made under that name. Right now you only need the one with wpcf-case-lender.

Should you need to retrieve values stored in custom fields that were not created in Types you can use the shortcode below.
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field

For non-types fields you can leave off the wpcf- prefix.

should my approach of adding a user field but swapping in the shortcode for the case lender field's value (ie the ID of the user selected in that dropdown list) rather than allowing it to use the default "current user in loop" value work?

I'm not quite clear on your statement above.

Thanks,
Shane

#2183027

Thanks for the clarification, I guess my confusion was the fact that the Toolset forms (add and update) which I had created were able to retrieve the value of the field but the view wasn't.

I'm not quite clear on your statement above.
Apologies, what I was meaning was that the custom field stores the ID of the user, therefore once the value was being correctly output it would be something like "45" instead of the name of that User. I was just checking that if I did something like this then it would display the name rather than the ID:

[wpv-user field="nickname" id="[types field='case-lender'][/types]"]

I tried this and confirmed that it works, the only extra bit of work I needed to do was to wrap it in a conditional as if there was no value for the "case-lender" field for a given record it would for some reason output the value for the current user instead - ie any cases which didn't have a "case lender" set would display "arcas web design" instead. So I had to use this:

[wpv-conditional if="( $(case-lender) ne '' )"][wpv-user field="nickname" id="[types field='case-lender'][/types]"][/wpv-conditional]
#2183157

Shane
Supporter

Languages: English (English )

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

Hi Simon,

Thank you for the clarity on the question.

How you're currently doing it is a perfectly acceptable way of displaying the user's nickname or any field from the user.

Thanks,
Shane

#2186715

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.