Saltar navegación

[Resuelto] How to access custom field group data to use in custom code?

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Client has a select custom field with various options that they want to access with custom code. Where can they find that data?

Solution:
The custom fields are stored in the wp_options table with a key of 'wpcf-fields'.

A sample entry is shown in the answer below: https://toolset.com/forums/topic/how-can-i-show-a-field-group-in-my-page/#post-620519

This support ticket is created hace 6 años, 10 meses. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por afernandez hace 6 años, 10 meses.

Asistido por: Nigel.

Autor
Mensajes
#620065
group.png

Hi

I have one field group called "Fields of Artistas" link to a CPT "artista". In this field group i have i field called "procedencia-artista". There is a select field with 3 items. I send you in attached file the description of this field in Toolset.

I want to show in one php page this items but i don´t want copy the values in a select tag of html.

I want to retrieve this values from toolset api or similar php function. As a result if a change the items of group i can show this changes in my php page doing nothing.

How can i do this?

Thanks in advance

#620103

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi there

I'm not sure I understand.

If you have a select custom field with several values, and then you publish posts which use this field, then when you view the post where you have inserted the custom field it will display the value as text (not as a select box).

What is that you want? To be able to display all the possible values from such a field on a page somewhere that is independent of the posts that use this field?

#620473

Hi Nigel

I try to explain better. I want to show the "procedencia-artista" values (Internacional, Nacional, Galicia) in a html select field. I want to know if it is possible retrieve this values from Toolset and show them in html page using php function by Toolset API. I want to use this select field to make a filter by "procedencia" in the web site.

I hope I explained it well

#620519

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Yes and no 🙂

The field group details are saved in wp_options (along with all of the other custom post fields) in a field with a key wpcf-fields.

It is stored as a serialized array (you can copy the entire value into a site such as unserialize.com to help visualise the data).

This is an example of how a simple field called "selection" stores the options.

Array (

    [selection] => Array
        (
            [id] => selection
            [slug] => selection
            [type] => select
            [name] => Selection
            [description] => 
            [data] => Array
                (
                    [slug-pre-save] => selection
                    [options] => Array
                        (
                            [wpcf-fields-select-option-d80a95b6de728ad683b83bed31285521-1] => Array
                                (
                                    [title] => First
                                    [value] => 1
                                )

                            [wpcf-fields-select-option-b48e55de6b01a48e2f2b7cdd972e19df-1] => Array
                                (
                                    [title] => Second
                                    [value] => 2
                                )

                            [wpcf-fields-select-option-bb5ef29d5716a625cadeecf9b6da43cc-1] => Array
                                (
                                    [title] => Third
                                    [value] => 3
                                )

                            [default] => no-default
                        )

                    [custom_use] => 
                    [conditional_display] => Array
                        (
                        )

                    [submit-key] => selection
                    [disabled_by_type] => 0
                )

            [meta_key] => wpcf-selection
            [meta_type] => postmeta
        )
)

So you could use get_option to retrieve the option and then extract the data you require (the titles of the options) and use that to build your own select box and echo that (or return it from a custom shortcode).

There is no API for this, it is not an expected use, but the data is there in the database if you want to reference it.

What I'm not clear about from your answer is where you say " I want to use this select field to make a filter by "procedencia" in the web site". Not a Views filter, right? You would just insert that in the filter editor of your View.

You are creating your own query and filtering?

#621250

Hi

Thanks a lot Nigel