Home Forums General Issues Meta_query to order by translated Select choices labels


Meta_query to order by translated Select choices labels

  • Hi! I need help for a multilingual meta_query order by… but need to know if it’s possible to use translated ACF “Select” labels for the ordered list.

    To be clear, I’ve a bilingual website (english and french) in development and want to display a list of members default ordered by Province (which are translated) and by last name for when members are from the same province.

    So I’ve this code :

    $query = new WP_Query(
    		'post_type' => 'members',
    		'meta_query' => array(
    			'relation' => 'AND',
    			'last_name_clause' => array(
    				'key' => 'members_last_name',
    			'province_clause' => array(
    				'key' => 'province_name',
    		'orderby' => array(
    			'province_clause' => 'ASC',
    			'last_name_clause' => 'DESC',

    So I use the Select custom field to select the province in the members custom posts, but given that we can’t translate SELECT custom field labels choices directly in admin, I outputed the php code of this group of custom fields and put it in functions.php and registered choices with the translation text-domain, it’s supposed to use “labels” as “return format”. Labels are translated when in my content loop but in code above, outside the loop, I don’t know how I could put it in the key => province in the code shown above.

    So for now, it doesn’t change the order of my query when switching from English to French.

    In English, it’ ok :

    Newfoundland & Labrador
    Nova Scotia
    Prince Edward Island

    In french, it seems to still use English labels for the order (meta query key) :


    Anyone could help me?

    Here are the translation for this custom field, so you see I registered the Custom field group in function.php to make it translatable :

    array (
    	'key' => 'field_5928316433e5c',
    	'label' => 'Province',
    	'name' => 'province',
    	'type' => 'select',
    	'instructions' => '',
    	'required' => 1,
    	'conditional_logic' => 0,
    	'wrapper' => array (
    		'width' => '',
    		'class' => '',
    		'id' => '',
    	'choices' => array (
    		'alberta' => __('Alberta','themechild'),
    		'british_columbia' => __('British Columbia','themechild'),
    		'house_of_commons' => __('House of Commons','themechild'),
    		'manitoba' => __('Manitoba','themechild'),
    		'new_brunswick' => __('New Brunswick','themechild'),
    		'newfoundland_and_labrador' => __('Newfoundland & Labrador','adamachild'),
    		'northwest_territories' => __('Northwest Territories','themechild'),
    		'nova_scotia' => __('Nova Scotia','themechild'),
    		'nunavut' => __('Nunavut','themechild'),
    		'ontario' => __('Ontario','themechild'),
    		'prince_edward_island' => __('Prince Edward Island','themechild'),
    		'quebec' => __('Quebec','themechild'),
    		'saskatchewan' => __('Saskatchewan','themechild'),
    		'senate' => __('Senate','themechild'),
    		'yukon' => __('Yukon','themechild'),
    	'default_value' => array (
    	'allow_null' => 0,
    	'multiple' => 0,
    	'ui' => 0,
    	'ajax' => 0,
    	'return_format' => 'label',
    	'placeholder' => '',


Viewing 1 post (of 1 total)

The topic ‘Meta_query to order by translated Select choices labels’ is closed to new replies.