I have the code that generates random posts from the specific tag,
global $post;
$postid = $post->ID;
$args = array(
'orderby' => 'rand',
'showposts' => 10,
'tag' => 'ABC',
'post__not_in' => array($postid)
);
query_posts($args);
echo '<ul>';
while (have_posts()) : the_post();
echo '<li><a href="'.get_permalink().'" title="'.the_title('','',false).'">'.the_title('','',false).'</a></li>';
endwhile;
echo '</ul>';
here the tag is ‘ABC’ but when i store ABC in a variable,
$tagABC = 'ABC';
and then call the variable here
global $post;
$postid = $post->ID;
$args = array(
'orderby' => 'rand',
'showposts' => 10,
'tag' => $tagABC,
'post__not_in' => array($postid)
);
query_posts($args);
echo '<ul>';
while (have_posts()) : the_post();
echo '<li><a href="'.get_permalink().'" title="'.the_title('','',false).'">'.the_title('','',false).'</a></li>';
endwhile;
echo '</ul>';
it doesn’t work this way , could someone explain why is it so ?
Are you sure you are using the same variable name? Notice that the following is working as expected:
Is given the following output:
Which as you can see the array
$argsand$args2have the same values and that means that the array that is passed to the function will be exactly the same if you use a variable or a string.