WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. fraserkc
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

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

    http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

    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