Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:50:50+00:00 2026-05-28T22:50:50+00:00

I have the code that generates random posts from the specific tag, global $post;

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:50:51+00:00Added an answer on May 28, 2026 at 10:50 pm

    Are you sure you are using the same variable name? Notice that the following is working as expected:

    $tagABC = 'ABC';
    
    $args = array(
    'orderby' => 'rand',
    'showposts' => 10,
    'tag' => 'ABC',             
    'post__not_in' => array(3)
    );
    
    $args2 = array(
    'orderby' => 'rand',
    'showposts' => 10,
    'tag' => $tagABC,             
    'post__not_in' => array(3)
    );
    
    var_dump($args2);
    var_dump($args);
    

    Is given the following output:

    array(4) {
      ["orderby"]=>
      string(4) "rand"
      ["showposts"]=>
      int(10)
      ["tag"]=>
      string(3) "ABC"
      ["post__not_in"]=>
      array(1) {
        [0]=>
        int(3)
      }
    }
    array(4) {
      ["orderby"]=>
      string(4) "rand"
      ["showposts"]=>
      int(10)
      ["tag"]=>
      string(3) "ABC"
      ["post__not_in"]=>
      array(1) {
        [0]=>
        int(3)
      }
    }
    

    Which as you can see the array $args and $args2 have 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code that generates a random number form 0-1 3 times and I
So right now I have this code that generates random letters in set increments
I have some php code that generates a random password. Next to a text
All, I have implemented a code that generates 2 random prime numbers and the
I have some code that generates image of a pie chart. It's a general
I have a code that generates errors on my PC but does't on other
I have some PHP code that generates dynamic tables of data on the fly.
I have some LINQ code that generates a list of strings, like this: var
I have some C# code that generates google maps. This codes looks at all
I have some PHP code that generates a calendar and then outputs html to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.