krsort error | WordPress.org

[ad_1]

Thread Starter
gm1980

(@gaurav1980)

Hi @gaurav1980,
I am not sure how this function is called (which hook and priority), but it appears to be executed before the $permalink_manager_uris global is populated with data. Because the variable’s value is null, ksort() returns an error.

You should keep two things in mind:

  1. Make sure the variable is indeed an array before trying to sort it
  2. Make sure that your code is called after the $permalink_manager_uris variable is filled with data

The “plugins_loaded” hook with priority 10 is the first time you can run the sorting function.

//* Permalink Manager Required
function pm_custom_uris_order() {
	global $permalink_manager_uris;

	if(is_array($permalink_manager_uris)) {
		krsort($permalink_manager_uris);
	}
}
add_action('plugins_loaded', 'pm_custom_uris_order', 10);

Best regards,
Maciej

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer