Title: post slug inside query posts
Last modified: August 24, 2016

---

# post slug inside query posts

 *  [Steelclover](https://wordpress.org/support/users/steelclover/)
 * (@steelclover)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/post-slug-inside-query-posts/)
 * Hi, i want to display all tags by its post slug.
 * So heres my code
 *     ```
       <?php query_posts( 'tag=RIGHTHERE' );
       while (have_posts()) : the_post();
           the_content( 'Read more' );
       endwhile; ?>
       ```
   
 * I want to display the post slug instead of RIGHTHERE
 * The Post Slug is right here
 *     ```
       <?php $slug = sanitize_title( get_the_title(), $fallback_title );
       echo $slug; ?>
       ```
   
 * Could anyone help me fixing this?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Steelclover](https://wordpress.org/support/users/steelclover/)
 * (@steelclover)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/post-slug-inside-query-posts/#post-6094526)
 * I modified the code a bit
 *     ```
       <?php query_posts( 'tag=RIGHTHERE' );
        while (have_posts()) : the_post();?>
       <a href="<?php the_permalink(); ?>"><?php the_title() ?></a>
       <?php endwhile; ?>
       <?php wp_reset_query();?>
       ```
   
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/post-slug-inside-query-posts/#post-6094603)
 * Hi Steelclover
 * Can you explain a bit more.
 * On what page do you want to do this?
    Is this for the main query of the page?
 * If it’s the single post page you can get the post slug whith this:
 *     ```
       <?php
       $slug = $post->post_name;
       echo $slug;
       ?>
       ```
   
 * The function query_posts() isn’t meant to be used by plugins or themes. Try to
   convert it to new WP_Query.
    [https://codex.wordpress.org/Function_Reference/WP_Query](https://codex.wordpress.org/Function_Reference/WP_Query)
 *     ```
       <?php
       $slug = $post->post_name;
       $the_query = new WP_Query( 'tag=' . $slug );
       while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
          <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       <?php endwhile; ?>
       <?php wp_reset_postdata(); ?>
       ```
   
 *  Thread Starter [Steelclover](https://wordpress.org/support/users/steelclover/)
 * (@steelclover)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/post-slug-inside-query-posts/#post-6094673)
 * Thanks for answering.
 * Example:
 * 1 Post Location
    1 Post Musical 1 Post Actor
 * I want to tag the actor with the musical and the location
    i want to tag the 
   musical with the actor and the location i want to tag the location with the actor
   and the musical
 * so finally the
 * actor post displays in what musicals and which location he plays in.
    location
   post displays what musical and actors plays in. musical post displays what actor
   and location its played in.
 * Normally a Tag is written the same way as the post_slug. so it would be very 
   easy to have all the related posts in my theme.
 * i know its hard to explain but i hope u understand what i am talking about.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/post-slug-inside-query-posts/#post-6094731)
 * Have you tried the code above?
 * It seems to me you want to have post to post relationships. Take a look at this
   plugin:
    [https://wordpress.org/plugins/posts-to-posts/](https://wordpress.org/plugins/posts-to-posts/)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘post slug inside query posts’ is closed to new replies.

## Tags

 * [post-slug](https://wordpress.org/support/topic-tag/post-slug/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/post-slug-inside-query-posts/#post-6094731)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
