WordPress.org

Ready to get started?Download WordPress

Forums

query_posts() Variables as Arguments (3 posts)

  1. DZaidle
    Member
    Posted 1 year ago #

    The following works perfectly:

    $current_issue = query_posts('tag=April+2012&category_name=Cover');

    What I cannot get to work is:


    $tag_var = 'April+2012';

    $current_issue = query_posts("tag=$tag_var&category_name=Cover");

    I've tried multiple variations such as:

    $tag_var = 'April+2012';

    $current_issue = query_posts('tag='.$tag_var.'&category_name=Cover');

    But nothing works. I get either an empty array or the fisrst "n" posts (where "n" = the default posts-per-page setting)

    Kudos and accolades for any help to make this work.

  2. simple1
    Member
    Posted 1 year ago #

    I'm interested in how this might work also.

  3. David Choi
    Member
    Posted 1 year ago #

    Try

    $current_issue = query_posts("tag={$tag_var}&category_name=Cover");

    So the PHP variable can be parsed when double quotes " are used.

    http://php.net/manual/en/language.types.string.php

Topic Closed

This topic has been closed to new replies.

About this Topic