Last active
          September 9, 2020 11:31 
        
      - 
      
- 
        Save fabriziofeitosa/dbd89811412efcecd8fdb7aa30016794 to your computer and use it in GitHub Desktop. 
    (WP) Popular select (ACF) com dados do wp_postmeta
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| // nome=NOME_DO_CAMPO_ACF | |
| add_filter('acf/load_field/name=nomes_dos_curadores', 'populateUserGroups'); | |
| function populateUserGroups( $field ) | |
| { | |
| // reset choices | |
| $field['choices'] = array(); | |
| // Pegar valor do wp_postmeta | 'key', 'id' | |
| $string = get_post_custom_values( '_group_vendors', '3973' ); | |
| $val = unserialize($string[0]); // decodifica | |
| $lista = array(); // Cria o array | |
| // Percorrer | |
| foreach ( $val as $key => $value ) { | |
| //echo "$key => $value <br />"; | |
| array_push($lista, "$value"); | |
| } | |
| // Juntar | |
| $listaFinal = implode(",", $lista); | |
| // Pegar Usuários via ID | |
| $users = get_users( [ 'include' => $listaFinal ] ); | |
| // Setar valores no select | |
| foreach ($users as $user) { | |
| $field['choices'][ $user->ID ] = $user->display_name; | |
| } | |
| return $field; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment