Ready to get started?Download WordPress


[resolved] Get post sulg and use it for a variable in multiple loops... ? (2 posts)

  1. SimonJ
    Posted 7 years ago #

    Ok... I don't know if I can do what I wanna do! :-)

    When I'm on my single.php, meaning I'm reading a particular post, I would like to get the post-slug of the post i'm reading and use it as a variable in query_posts later in the page.

    I wanna use the post-slug of a particular posts as a tag in other posts, wich are relative to this post...

    Example :

    I'm reading the post XYZ, with the post-slug XYZ. So I have a first loop to display it:

    <?php while (have_posts()) : the_post(); ?>
    Display the post's stuff
    <?php endwhile; ?>

    Then,on this same page, after this first loop, I want to put other loops to display all posts using the post-slug of the first post as a tag...

    'tag_slug__and'=>array('the-slug-of-the-post-looped-above '),
    ) );


    <?php query_posts('tag=the-slug-of-the-post-looped-above'); ?>

    Don't know if I'm clear enough... :-) It is possible ?



  2. SimonJ
    Posted 7 years ago #

    Ok! Well... :-)

    I think I was able to find the answer by myself...

    I found this thread :


    There, I found a fucntion to get the post slug...

    Then, in my loops, I tried that :

    'tag_slug__and'=>array((the_slug() )),
    ) );

    And it works... :-)

    If any WP guru could confirm me that it's an orthodox way to do so, I would be glad... :-)


Topic Closed

This topic has been closed to new replies.

About this Topic