• 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

    (@steelclover)

    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

    (@keesiemeijer)

    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

    <?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

    (@steelclover)

    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

    (@keesiemeijer)

    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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘post slug inside query posts’ is closed to new replies.