Help get_the_terms wordpress

0

Good I have this code in php, and it is the root of having the sectors will leave some icons or others. But I do not know how to get the sectors with get_the_terms. The taxonomy is sectors.

echo ("<div class='iconos-sectores' style='display:flex;width:100%; 
 margin-top:20px;'>");
                "sectores" => get_the_terms( $post->ID, 'sectores' );
    echo ("</div>");
    
asked by Caldeiro 17.08.2018 в 11:42
source

1 answer

0

The way to use get_the_terms () is to pass it as a parameter the ID of post and the name of the taxonimía , in your case sectores .

foreach (get_the_terms(get_the_ID(), 'sectores') as $sector) {
    print_r($sector);
}

This will return an object whose properties are the following, this is the content of the variable $sector :

WP_Term Object
(
[term_id]          => 'xxx'
[name]             => 'xxx'
[slug]             => 'xxx'
[term_group]       => 'xxx'
[term_taxonomy_id] => 'xxx'
[taxonomy]         => 'xxx'
[description]      => 'xxx'
[parent]           => 'xxx'
[count]            => 'xxx'
[filter]           => 'xxx'
)

If what you want is to assign an icon according to the name (I have not been very clear what you ask) you can do something like this:

echo ("<div class='iconos-sectores' style='display:flex;width:100%; margin-top:20px;'>");
    foreach (get_the_terms(get_the_ID(), 'sectores') as $sector) {
     if($sector->name === 'nombre_buscado'){
      echo ("Icono Deseado");
      }
    }
echo ("</div>");
    
answered by 17.08.2018 / 13:39
source