• I would like to create a search function that takes the values of 2 fields from a form of mine ($_REQUEST['VST1'] and $_REQUEST['VST2']) and searches for them as tags.

    I’ve looked through the codex, and it looks like I need to somehow put them into the query_posts(tag=''); query.

    I don’t believe echo-ing them into the query works – like I’ve tried below:

    query_posts(tag='echo $_REQUEST['VST1']'+'echo $_REQUEST['VST2']');

    What will work?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Try this:

    query_posts("tag={$_REQUEST['VST1']}+{$_REQUEST['VST2']}");

    Thread Starter thebillevard

    (@thebillevard)

    I’ll give it a try, thanks!

    <?php
     $tgs = array();
     $tgs[] = get_query_var('VST1');
     $tgs[] = get_query_var('VST2');
     $tags = implode(",",$tgs);
    query_posts('tag='.$tags);
    ?>
    Thread Starter thebillevard

    (@thebillevard)

    got it working, thank you both for the help. The working solution was:

    <?php
     $tgs = array();
     $tgs[] = $_REQUEST['VST1'];
     $tgs[] = $_REQUEST['VST2'];
     $tags = implode(",",$tgs);
    query_posts('tag='.$tags);
    ?>
    Thread Starter thebillevard

    (@thebillevard)

    actually, both of your codes worked, but for some reason only 1 tag is being queried.

    According to the Codex, when the tags are delimited by commas, it fetches posts that have either tag. When they are delimited by a plus sign, it fetches posts having both tags.

    The code you posted above does the first option. If you want the second, change this line:

    $tags = implode(",",$tgs);

    to:

    $tags = implode("+",$tgs);

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Query Post Tags’ is closed to new replies.