Support

Account

Home Forums General Issues Can’t sort with an ACF field? Reply To: Can’t sort with an ACF field?

  • There was an error sorry :

    function custom_order_by_acf_field_query($query) {
        if (!is_admin() && isset($query->query_vars['orderby'])) {
    		// Récupérer le champ ACF entre {{}}
    		$orderby_field = str_replace(array('{{', '}}'), '', $query->query_vars['orderby']);
    		 if ( $orderby_field != $query->query_vars['orderby']) {
    			$query->set('meta_key', $orderby_field);
    			$query->set('orderby', 'meta_value_num');
    		 }
        }
    }