I use WordPress Multisite and made a plugin that adds columns with some data. My code is based on this WP Engineer article.

The key function in WordPress Multisite is manage_sites_custom_column. And the problem is that I want to be able to sort the column I created.

I tried the code in this Scribu's article but it is based on manage_posts_custom_column for single sites.


I tried to solve this issue before. Taking a second look at it, we can alter the sites list using the query filter hook.

Supposing our custom sort URL is

add_action( 'plugins_loaded', function()
    global $pagenow;
        && 'sites.php' == $pagenow
        && isset( $_GET['orderby'] ) 
        && 'site_category' == $_GET['orderby'] 
        add_filter( 'query', 'b5f_filter_site_query' );

function b5f_filter_site_query( $query )
    global $wpdb;
    if( FALSE !== strpos( $query, "SELECT * FROM {$wpdb->blogs} WHERE site_id = '1'  LIMIT 0, 20" ) )
        $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '1'  ORDER BY mature DESC LIMIT 0, 20";
    return $query;

Yes, I'm playing with the mature column. Probably, a refined SQL query could be made, but not my league... This column is a TINYINT(2). WordPress recognizes 0 and 1, leaving us with 98 options. In my case, enough to categorizing.

If mature > 1, the site is marked as such in site-info.php, but not in sites.php. I'm not really sure how being mature affects the site output.
A workaround to use the mature column liberally is to tell WordPress everything is ok, don't worry, outside the sites.php screen:

add_action( 'plugins_loaded', function()
    global $pagenow;
    if( 'sites.php' != $pagenow )
        add_filter( 'blog_details', 'b5f_hack_mature_queries' );

    # Hide the Mature checkbox in site-info.php
    add_action( 'admin_footer', 'b5f_print_sites_footer' );

function b5f_hack_mature_queries( $details )
    $details->mature = 0;
    return $details;

function b5f_print_sites_footer()
    if( 'site-info-network' != get_current_screen()->id )

echo <<<HTML
    <script type="text/javascript">
        jQuery(document).ready( function($) {
| improve this answer | |

Not a full answer... but for others searching for how to alter the sortability of the "sites" page.

The following does not work as expected:

add_filter('manage_sites_sortable_columns', ...

Instead, try:

add_filter('manage_sites-network_sortable_columns', ...
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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