Skip Navigation

[Résolu] Populate Select Field based on PostType

This support ticket is created Il y a 8 années et 5 mois. 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 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 réponses, has 2 voix.

Last updated by Jaffa Il y a 8 années et 5 mois.

Assisted by: Waqas.

Auteur
Publications
#342644

Is it possible to create custom field options with information included in a custom post type?

E.g., if I want to ask people what country they come from, can I include a select box (or even check/radio boxes) that uses values from CPT "Countries" or do I need to enter the values manually?

I need the select box to appear in amongst other fields for this group and not just as a last option contained in a field called Relationship at the base of the page, there are currently no options to select from the post types when adding a select field only adding manual or conditional.

Help appreciated as this task is so simple in ACF,

#342665

Waqas
Supporter

Languages: Anglais (English )

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

Yes you can populate such options in a SELECT field. Please consider followings sample code:

function my_wpt_field_options( $options, $title, $type )
{
    switch( $title )
    {
    case 'a name of select field':
        $options[] = array(
            '#value' => 'xxx',
            '#title' => 'dynamic add some option',
        );
        break;
    case 'a name of radio option':
        $options[] = array (
            '#value' => 'xxx',
            '#title' => 'dynamic added radio',
            '#validate' => array (),
            '#after' => '',

        );
        break;
    }
    return $options;
}
add_filter('wpt_field_options', 'my_wpt_field_options', 10, 3);

The above code demonstrates the case of SELECT and Radio fields. You can remove the other part (i.e. radio field). While in the SELECT field section you should use WordPress code to get titles of your posts, so you can populate required options. Please see https://codex.wordpress.org/Template_Tags/get_posts

You need to add this code in your theme's functions.php file to make it work.

#343472

Great Thank you,

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.