Query Posts by php the_title - How can I make this work? (2 posts)

  1. fraserkc
    Posted 3 years ago #

    How can I make it so that I can query my posts by a tag that uses the title of a band name?

    Basically like this,

    tag = hootieandtheblowfish
    band name = Hootie And The Blowfish

    <?php query_posts($query_string . 'tag=<?php
    $band = '<?php the_title() ?>';
    $string = preg_replace('/\s+/', '', $band);
    echo $string
    ?>&posts_per_page=24'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    so I get I need to eliminate the white spaces, but can I search by a <?php> request like that or is there any way to do so?

    I think it may require some sort of double loop or something to get one variable and then apply it to the next, but I just don't know. Case of the Mondays I guess....

    Hope this makes sense....

  2. racer x
    Posted 3 years ago #

    You don't want to do it that way. WordPress already has a method for querying by tag or many other things.


    Also, never assign a variable using a function that outputs data such as $band = the_title(). Always use the get version such as get_the_title().

Topic Closed

This topic has been closed to new replies.

About this Topic