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

  • SEARCH
  • Home
  • 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 7187709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:54:25+00:00 2026-05-28T18:54:25+00:00

I’m trying to put the ID from code 1 in to code 2. Can

  • 0

I’m trying to put the ID from code 1 in to code 2. Can anyone help me? The ID is the logged in user ID. I want to re-use this ID in code 2. As you can see code 2 got ID 1 at the moment, but I need to assign the ID given from code 1 in to code 2 in stead of the ID “1”

Code1:

<?php $user_info = get_userdata(1); echo 'User ID: ' . $user_info->ID . "\n"; ?>

Code2:

<?php
$user_id = 1;
$user_blogs = get_blogs_of_user( $user_id );
echo 'User '.$user_id.'\'s blogs:<ul>';
foreach ($user_blogs AS $user_blog) {
    echo '<li>'.$user_blog->blogname.'</li>';
}
echo '</ul>';
?>

The code will be placed in the same file. I’m trying to merge these 2 insted of using ID 1 in code 2

  • 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-28T18:54:26+00:00Added an answer on May 28, 2026 at 6:54 pm

    You are doing it wrong here. Your code one gives id of the current blog not the user. You need to change your code;

    CODE 1:

    $user_id = get_current_user_id(); //get the current logged in user id
    

    CODE 2:

    $user_blogs = get_blogs_of_user( $user_id ); //get the blogs of logged in user
    echo 'User '.$user_id.'\'s blogs:<ul>';
       foreach ($user_blogs as $user_blog) {
           echo '<li>'.$user_blog->blogname.'</li>';
       }
    echo '</ul>';
    

    Hope this is what you want 🙂

    EDIT :

    This is your current code:

    CODE 1:

     <?php 
         $user_info = get_userdata(1); 
         echo 'User ID: ' . $user_info->ID . "\n"; 
      ?> 
    

    CODE 2:

       <?php $user_id = 1; 
             $user_blogs = get_blogs_of_user( $user_id ); 
             echo 'User '.$user_id.'\'s blogs:<ul>'; 
             foreach ($user_blogs AS $user_blog) { echo '<li>'.$user_blog->blogname.'</li>'; } echo '</ul>'; 
        ?>
    

    Here you are assigning $user_id =1 directly. No need of that. You can do that directly in code 1.

    Just change your current code to this:

    CODE 1:

     <?php 
         $user_id = get_current_user_id(); //get the current logged in user id
         echo 'User ID: ' . $user_id . "\n"; 
     ?> 
    

    CODE 2:

       <?php 
             $user_blogs = get_blogs_of_user( $user_id ); 
             echo 'User '.$user_id.'\'s blogs:<ul>'; 
             foreach ($user_blogs AS $user_blog) { echo '<li>'.$user_blog->blogname.'</li>'; } echo '</ul>'; 
        ?>
    

    This will work provided your both codes are in same file.

    This is what you want

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put

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.