Support » Fixing WordPress » Using a variable inside WP_Query

  • Howdy, wondering how I can use a php variable that I have predefined in the middle of a wp_query statement? Basically I’m creating a custom “related posts” kind of thing that finds posts with shared tags. (Only one specific tag is stored in the variable.) Here’s the code I’m working with below:

    <?php $posts_query2 = new WP_Query('tag=news+$myvariable&paged=$paged&showposts=4'); ?>

    The statement works fine when I take away the variable and test it by putting in the exact statement that I want to be there. I also know the variable is working fine by doing an echo statement in the post.

    I’m using a php variable elsewhere to pull up related links, and it works fine in the wp_list_bookmarks statement, but for some reason its not working in wp_query, any ideas why?

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using a variable inside WP_Query’ is closed to new replies.