2 added 41 characters in body
source | link

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. How can I get the page slug? Thank-you!

This code would work if I have triedonly had 'day-courses' in this custom taxonomy, but it doesn't workwhich 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' => '$post_slug''day-courses' ) );
while ($my_query->have_posts()) : $my_query->the_post();
?>
<div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div>
<?php endwhile; ?>

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. How can I get the page slug? Thank-you!

I have tried this, but it doesn't work:

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

$my_query = new WP_Query( array( 'post_type' => 'event',  'event-categories' => '$post_slug' ) );
while ($my_query->have_posts()) : $my_query->the_post();
?>
<div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div>
<?php endwhile; ?>

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="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div>
<?php endwhile; ?>
1
source | link

How to get the page slug of the current archive page for a custom taxonomy

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. How can I get the page slug? Thank-you!

I have tried this, but it doesn't work:

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

$my_query = new WP_Query( array( 'post_type' => 'event',  'event-categories' => '$post_slug' ) );
while ($my_query->have_posts()) : $my_query->the_post();
?>
<div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div>
<?php endwhile; ?>