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
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:
CODE 2:
Hope this is what you want 🙂
EDIT :
This is your current code:
CODE 1:
CODE 2:
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:
CODE 2:
This will work provided your both codes are in same file.
This is what you want