¿Cómo obtengo el id de término taxonómico actual en wordpress?


He creado una taxonomía.página php en mi carpeta de plantillas de wordpress, me gustaría obtener el id de término actual para una función. Cómo puedo conseguir esto?

get_query_var('taxonomy') solo devuelve el término slug, quiero el ID

Author: Imran, 2012-09-06

7 answers

No importa! Lo encontré:)

get_queried_object()->term_id;
 232
Author: Imran,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-05 20:32:02

Aquí está todo el fragmento de código necesario:

$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
 33
Author: Tim Bowen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-22 01:15:39

Simple y fácil!

get_queried_object_id()
 18
Author: theMukhiddin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-21 13:27:12

¡Solo copie y pegue el código debajo!

Esto imprimirá el nombre y la descripción de su taxonomía actual (opcional)

<?php 
   $tax = $wp_query->get_queried_object();
   echo ''. $tax->name . '';
   echo "<br>";
   echo ''. $tax->description .''; 
?>
 5
Author: Varsha Dhadge,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-31 16:54:52
<?php 
$terms = get_the_terms( $post->ID, 'taxonomy');
foreach ( $terms as $term ) {
    $termID[] = $term->term_id;
}
echo $termID[0]; 
?>
 4
Author: Jadson Moreira,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-03-16 00:02:18

Véase wp_get_post_terms(), usted haría algo así:

global $post;
$terms = wp_get_post_terms( $post->ID, 'YOUR_TAXONOMY_NAME',array('fields' => 'ids') );

print_r($terms);
 0
Author: purvik7373,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-24 09:32:47

Es el término babosa que quieres.Parece que puede obtener el id de esta manera si eso es lo que necesita:

function get_term_link( $term, $taxonomy = '' ) {
    global $wp_rewrite;

    if ( !is_object($term) ) {
        if ( is_int( $term ) ) {
            $term = get_term( $term, $taxonomy );
        } else {
            $term = get_term_by( 'slug', $term, $taxonomy );
        }
    }
 0
Author: SYED FARHAN KARIM,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-10 14:39:53