Home Forums ACF PRO conditional sort Reply To: conditional sort

  • What you’re trying to do can’t really be done, basically because sorting posts by two different meta keys and intermixing them in WP is beyond what WP is capable of. However, you can do this by saving the value of org_name in the last_name field when the post is saved.

    add_filter('acf/update_value/name=org_name', 'insert_org_into_last_name', 10, 3);
    function insert_org_into_last_name($value, $post_id, $field) {
        // replace the value of $last_name_field_key
        // with the field key of the last name field
        $last_name_key = "field_123456789ABCD";
        update_field($last_name_key, $value, $post_id);
        return $value;

    Now you can do a query and sort by last name. The value in last name will not be seen because it’s in a conditional field.