筛选器‘REQUEST’和‘PARSE_QUERY’不会在sites.php或link-ranger.php中触发

时间:2012-05-02 作者:brasofilo

我在试着sortable columns 在网站和链接列表管理页面中。

/wp-admin/network/sites.php/wp-admin/link-manager.php

问题是这些屏幕中没有启动以下过滤器,从而阻止了查询修改。是否有其他方法可以使用?

function site_category_column_orderby( $vars ) {
    //global $firephp;
    //$firephp->log($vars, \'vars\');
    if ( isset( $vars[\'orderby\'] ) && \'site_category\' == $vars[\'orderby\'] ) {
        $vars = array_merge( $vars, array(
            \'meta_key\' => \'site_category\',
            \'orderby\' => \'meta_value_num\'
        ) );
    }
    return $vars;
}
add_filter( \'parse_query\', \'site_category_column_orderby\' );


function link_thumbnail_column_orderby( $vars ) {
    if ( isset( $vars[\'orderby\'] ) && \'link_thumbnail\' == $vars[\'orderby\'] ) {
        $vars = array_merge( $vars, array(
            \'meta_key\' => \'link_thumbnail\',
            \'orderby\' => \'meta_value_num\'
        ) );
    }
    return $vars;
}
add_filter( \'request\', \'link_thumbnail_column_orderby\' );

[UPDATE]

我想对该插件的a链接列进行排序:https://wordpress.stackexchange.com/a/50389/12615

和另一个的a站点列:https://wordpress.stackexchange.com/a/50936/12615

1 个回复
最合适的回答,由SO网友:brasofilo 整理而成

我设法订购了链接管理器。通过使用以下内容的自定义列创建php:

/* 
 * Sort links using the custom column link_image
 */
function sort_on_field(&$objects, $on, $order = \'ASC\') { 
    $comparer = ($order === \'DESC\') 
        ? "return -strcmp(\\$a->{$on},\\$b->{$on});" 
        : "return strcmp(\\$a->{$on},\\$b->{$on});"; 
    usort($objects, create_function(\'$a,$b\', $comparer)); 
}

function brsfl_link_manager_order($links) {
    global $current_screen;
    if($current_screen->id == \'link-manager\' && $_GET[\'orderby\'] == \'link_image\') {
        $order = ($_GET[\'order\'] === \'asc\') ? \'ASC\' : \'DESC\';
        sort_on_field($links, \'link_image\', $order);
    } 
    return $links;
} 

if(is_admin()) add_filter(\'get_bookmarks\',\'brsfl_link_manager_order\');
对于站点。php清单,事情似乎更棘手。。。我找到了一个interesting code 在里面this thread, 但最终使其与:

public function callback_for_plugins_loaded()
{
    global $pagenow;
    if( 
        is_super_admin() 
        && \'sites.php\' == $pagenow
        && isset( $_GET[\'orderby\'] ) && \'site-category\' == $_GET[\'orderby\'] 
    ) 
        add_filter( \'query\', array( $this, \'filter_site_query\' ) );
}

public function filter_site_query( $query )
{
    global $wpdb;
    $search_query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = \'1\'  LIMIT 0, 20";

    if( isset( $_GET[\'order\'] ) )
        $order = ( \'asc\' == $_GET[\'order\'] ) ? \'ASC\' : \'DESC\';
    else
        $order = \'DESC\';

    if( strpos( $query, $search_query ) !== FALSE )
        $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = \'1\'  ORDER BY mature $order LIMIT 0, 20";

    return $query;
}
我正在使用该列wp_blogs.mature 作为index for site categories. 我想可以进行更复杂的查询,但现在该列似乎没问题。

结束