WordPress.org

Ready to get started?Download WordPress

Forums

PHP Variable in WP_Query (3 posts)

  1. joshuaonesix
    Member
    Posted 4 years ago #

    The blog im working on will be highlighting some items. For every item there will be 3 posts (Story, Blog, Press Release) I want to display them on one page based on the story. The 3 posts will have a unique tag only unique to that item. Ive figured out how to generate that tag based on pulling it from the story. Now i need to get it added to the other queries. The code below works with the tag hard coded in:

    $my_query = new WP_Query('cat=10&tag=uniquetag');
    	while ($my_query->have_posts()) : $my_query->the_post();
    	the_content();
    	endwhile;

    but not when used with the php variable

    $my_query = new WP_Query('cat=10&tag='.$myvariable);
    	while ($my_query->have_posts()) : $my_query->the_post();
    	the_content();
    	endwhile;
  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Where/how are you setting up $myvariable?

  3. joshuaonesix
    Member
    Posted 4 years ago #

    this is before the end of the first loop.

    <?php
    $posttags = get_the_tags();
    $count=0;
    	if ($posttags) {
    	foreach($posttags as $tag) {
    		$count++;
    	if (1 == $count) {
    
    		$mytag = $tag->name . ' ';
    
    		echo $mytag;
    					}
    								}
    					}
    
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic