In my plugin, in init action I use get_sites() function... however it throws:

Call to undefined function get_sites() in XYZ on line 154 whats solution?

1) The same happens with wp_get_sites()...
2) no help when I use require_once(ABSPATH . 'wp-includes/ms-blogs.php');
3) I use wordpress version 4.6

  • 1
    What version of WordPress is being used? Where is get_sites() being called (which hook)? Nov 17, 2016 at 8:11
  • in init as i said ( version 4.6). I doubt problem is that the function is called within non MULTI-SITE site....
    – T.Todua
    Nov 17, 2016 at 8:13

3 Answers 3


Solution seems to be:

if(function_exists('get_sites'))         {$sites= get_sites();} 
elseif(function_exists('wp_get_sites'))  {$sites= wp_get_sites();} 
  • 1
    This will not work properly, as the deprecated function still exists in WP 4.6+. Better to test for the WP version (also see my answer below). Jan 4, 2018 at 19:57
  • If the deprecated function still exists, then it's usable. When it is not available any more, then it will stop working and the alternative will be chosen. Mar 28, 2019 at 14:10

The wp_get_sites function was deprecated in WP 4.6. The full answer is the first answer here: Sorting list of sites from multisite network using wp_get_sites .

Also, the function provided by Lance Cleveland (in the answers in the above link) provides a test for the proper function to use. But it is incomplete, as the old function is deprecated so the old function still exists if pre-4.6. The test should look for the WP version, not the existence of the function. (See my answer to the same question.)

I have a plugin for multisites that looped through the sites. The pre-4.6 code was causing problems on 4.6+ site, so changed the plugin's requirements to require WP 4.6 or later. The plugin automatically deactivates with a message if pre-4.6 is found.

That said, keeping WP updated is strongly recommended. There are security risks (and compatibility issues) with not doing updates.

  • Testing for the version is generally the wrong way to go about detecting which function to use. A simple search on the web will show that the concept of object detection is superior over version detection for many different frameworks, programming languages, and implementations. Proven many times over. Mar 28, 2019 at 14:08
  • But I didn't recommend checking the version of the browser or JS, as your links discuss. I said to check the WP version, which will tell you which method to use. Checking for the existence of the function will not fully work in all instances, as the function will still be there in 4.6+, but won't work right. So checking for the WP version is the best way, IMHO. Mar 28, 2019 at 17:40
  • Again, I was referring to the concept not the languages or the frameworks. Mar 28, 2019 at 20:51

The get_sites() function (replacing the wp_get_sites() function, deprecated) only works in a context of a network of sites.

You can create a network by using the multisite feature, following those instructions in the Codex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.