Skip Navigation

[Résolu] How to test, retrieve and update values that are "drop down select" field types

This support ticket is created Il y a 3 années et 9 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Ce sujet contient 1 réponse, a 1 voix.

Dernière mise à jour par PaulS4783 Il y a 3 années et 9 mois.

Auteur
Publications
#1966161

This code isn't working for me.

$country = get_post_meta( $post_id, 'wpcf-consignee-country', true );
        if ($country == '--- not set ---') {
                $country = do_shortcode("[types field='client-country' output='raw' item='@client-username-vehicle.parent'][/types]");
                $country = strval( $country );
                update_post_meta( $post_id, 'wpcf-consignee-country', $country );
        }

I have two post types Clients and Vehicles, connected by a post reference field.
I want the code to test to see if the "Consignee Country" field of the Vehicle record is blank.
And if it is blank, look up the "Country" field from the parent "Client" record and use that instead.

The above code works absolutely fine if the

$country

variable is string.

But in this case the input field is a drop down selector.
I have tried:

 if ($country == '--- not set ---')

and

 if ($country == '')

but neither work.

What am I missing here?
Is this part of the problem:

$country = strval( $country );

?

#1966169

Solved.
My bad. One of the field slugs was misnamed.

if ($country == '')

works fine.