Filter element from taxonomy in wordpress

0

In the article page (single.php) of my theme I have the following code that filters a div making it appear only on pages of a certain category:

<?php $categoria_post = the_category_id($categoria_post);
if ($categoria_post == 760) : ?>
<div>
...
</div> 
<?php endif; ?>

I need to filter a div in a similar way, however from the slug of a taxonomy (series_exp), ignoring the id.

Something similar, but filtered only by the slug:

EDITED

Form this custom taxonomy was created:

add_action( 'init', 'create_post_tax' );

function create_post_tax() {
    register_taxonomy(
        'series_especiais',
        'post',
        array(
            'label' => __( 'Séries Especiais' ),
            'rewrite' => array( 'slug' => 'series_especiais','with_front' => true ),
            'hierarchical' => true,
        )
    );
}
    
asked by anonymous 06.07.2016 / 00:23

2 answers

0

If you have the ID of the category in $categoria_post , you can use the get_category()

$categoria = get_category($categoria_post)

and access it with

$categoria['slug']

Just remember that the_category_id() is a deprecated method, so it's worth re-evaluating your code. Since you're in single.php , it makes more sense to use the wp_get_post_categories() method. Using the_ID() is as simple as

$cats = wp_get_post_categories(the_ID());

$cats is an array (even if the post has only one category). From there, get the slug and make your filter.

    
06.07.2016 / 02:50
0

The problem was solved by a user of the English wordpress forum (https://wordpress.stackexchange.com / users / 46066 / tim-malone) .

The solution was as follows:

<?php
$especiais = get_the_terms( $post, 'series_especiais' );
if( is_array( $especiais ) && count( $especiais ) ) : ?>

Solution's original link:

link

    
12.07.2016 / 02:03