WordPress Multisite – global categories

function __add_global_categories( $term_id ) { if ( get_current_blog_id() !== BLOG_ID_CURRENT_SITE || ( !$term = get_term( $term_id, ‘category’ ) ) ) return $term_id; // bail if ( !$term->parent || ( !$parent = get_term( $term->parent, ‘category’ ) ) ) $parent = null; global $wpdb; $blogs = $wpdb->get_col( “SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = ‘{$wpdb->siteid}'” ); foreach … Read more

How to disable a network enabled plugin for just one site?

You can use the filter site_option_*. E.g. the following will disable akismet on blog with id 2. add_filter(‘site_option_active_sitewide_plugins’, ‘modify_sitewide_plugins’); function modify_sitewide_plugins($value) { global $current_blog; if( $current_blog->blog_id == 2 ) { unset($value[‘akismet/akismet.php’]); } return $value; }

Can i merge 2 new WP_Query($variable) ‘s?

You won’t do much good just merging the arguments, you need to merge the resulting posts array and the post_count count. This works for me: //setup your queries as you already do $query1 = new WP_Query($args_for_query1); $query2 = new WP_Query($args_for_query2); //create new empty query and populate it with the other two $wp_query = new WP_Query(); … Read more

Running WP Cron on multisite the right way

I think the best way is to use WP-CLI but you’d need to write a bash script to do this. Here is one that should do it for you: WP_PATH=”/path/to/wp” for SITE_URL in = $(wp site list –fields=domain,path,archived,deleted –format=csv –path=”$WP_PATH” | grep “,0,0$” | awk -F ‘,’ ‘{print $1 $2}’) do for EVENT_HOOK in $(wp … Read more

‘Global’ settings page for multisite plugin

As a reference To create network or global settings, you need to do the following Add a settings page add_submenu_page( ‘settings.php’… # cf options.php for blog level` Add a global option add_site_option($key,$value) Update a global option update_site_option($key,$value) Get a site option get_site_option($key) Global settings are saved to the sitemeta table (individual blog settings are saved … Read more

restore_current_blog() vs switch_to_blog()

After every instance of switch_to_blog() you need to call restore_current_blog() otherwise WP will think it is in a “switched” mode and can potentially return incorrect data. If you view the source code for both functions you will see those functions push/pop data into a global called $GLOBALS[‘_wp_switched_stack’]. If you do not call restore_current_blog() after every … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)