Ver Mensaje Individual
  #3 (permalink)  
Antiguo 12/04/2016, 17:14
zaezRain
 
Fecha de Ingreso: noviembre-2015
Mensajes: 4
Antigüedad: 8 años, 6 meses
Puntos: 0
Respuesta: Error con get_terms()

Cita:
Iniciado por metacortex Ver Mensaje
Te tira un false porque seguramente tus categorías están vacías. Debes definir el parámetro "hide_empty" a "0" porque viene en "1" por defecto, házlo así:

Código PHP:
Ver original
  1. $tax_terms = get_terms( $taxonomy , array('hide_empty' => 0) );
o así (es la misma cosa):
Código PHP:
Ver original
  1. $tax_terms = get_terms( $taxonomy , 'hide_empty=0' );
Qué tal, el problema era que las taxonomias no cargaban a tiempo y por eso aparecia vacio, lo logre solucionar con el siguiente codigo:


Código PHP:
add_action('init''my_acf_add_local_field_groups_niño'9999);

function 
my_acf_add_local_field_groups_niño() {

    
$tax_terms get_terms('niño',array('hide_empty' => 0,));
    
$args = array(
      
'key' => 'group_niño',
      
'title' => 'Niño',
      
'fields' => array(),
      
'location' => array(
        array(
          array(
            
'param' => 'post_type',
            
'operator' => '==',
            
'value' => 'psicologos',
          ),
        ),
      ),
    );

    foreach (
$tax_terms as $tax_term) {
        
$args['fields'][] = array(

            
'key' => 'field_'.$tax_term->slug,
            
'label' => $tax_term->name,
            
'name' => $tax_term->slug,
            
'type' => 'textarea',
            
'wrapper' => array (
  
'width' => '50%',
  
'class' => $tax_term->slug,
  
'id' => $tax_term->slug,
),

        );
    }
     
acf_add_local_field_group($args);