WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. SimonJ
    Member
    Posted 6 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...

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

    Or

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

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

    Thanks.

    S.

  2. SimonJ
    Member
    Posted 6 years ago #

    Ok! Well... :-)

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

    I found this thread :

    http://wordpress.org/support/topic/128046?replies=6

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

    Then, in my loops, I tried that :

    <?php
    query_posts(array(
    'cat'=>'12',
    '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... :-)

    S.

Topic Closed

This topic has been closed to new replies.

About this Topic