I have a custom post type and custom taxonomy. The taxonomy works like a category system. Users can add the custom posts to the categories. There is one page per each category, displaying the posts in that category.

I need to get the page slug of the current category page. How can I do this please?

For example, my url is: ?event-categories=day-courses.

event-categories is the custom taxonomy.

This code would work if I only had ‘day-courses’ in this custom taxonomy, which I do not:

<?php
 global $post;
    $post_slug=$post->post_name;
    echo $post_slug; 

$my_query = new WP_Query( array( 'post_type' => 'event',  'event-categories' => 'day-courses' ) );
while ($my_query->have_posts()) : $my_query->the_post();
?>
<div>
<h2><a href="https://wordpress.stackexchange.com/questions/175108/<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div>
<?php endwhile; ?>

1 Answer
1

Using your current code:

$tax_slug = get_query_var( 'event-categories' );

Leave a Reply

Your email address will not be published. Required fields are marked *