• I am trying (for the last three hours) to write a PHP script that will simply count the number of sites/blogs a user has created on my site and set it to a variable so I can compare it.

    $count = get_sites(array(‘site_in’ => $user_id, ‘count’ => true));

    This is what I have. It only returns the number 2. regardless of how many sites are actually created by a user.

Viewing 2 replies - 1 through 2 (of 2 total)
  • site_in is an argument for an array of site ID’s to pool, not a user ID.

    get_blogs_of_user() looks like it’s what you’re after. I was able to get as requested with the following:

    add_action( 'init', 'ds_current_user_sites');
    function ds_current_user_sites() {
    	$user = get_current_user_id();
    	$sites = get_blogs_of_user($user);
    	$count = count($sites);
    	echo $count;
    }

    Update: sorry I read your post wrong, the above counts users who are users within a site, not that they are the one who created the site.

    • This reply was modified 7 years, 4 months ago by David Sword.
    • This reply was modified 7 years, 4 months ago by David Sword.
    Moderator bcworkz

    (@bcworkz)

    Get a count of the return of get_blogs_of_user() ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP Counting sites’ is closed to new replies.