本文整理匯總了PHP中WP_User_Query::set方法的典型用法代碼示例。如果您正苦於以下問題:PHP WP_User_Query::set方法的具體用法?PHP WP_User_Query::set怎麽用?PHP WP_User_Query::set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WP_User_Query
的用法示例。
在下文中一共展示了WP_User_Query::set方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1:
function test_exclude()
{
$users = new WP_User_Query();
$users->set('fields', '');
$users->set('exclude', $this->user_id);
$users->prepare_query();
$users->query();
$ids = $users->get_results();
$this->assertNotContains($this->user_id, $ids);
}
示例2:
function test_get_and_set()
{
$users = new WP_User_Query();
$this->assertEquals('', $users->get('fields'));
$this->assertEquals('', @$users->query_vars['fields']);
$users->set('fields', 'all');
$this->assertEquals('all', $users->get('fields'));
$this->assertEquals('all', $users->query_vars['fields']);
$users->set('fields', '');
$this->assertEquals('', $users->get('fields'));
$this->assertEquals('', $users->query_vars['fields']);
$this->assertNull($users->get('does-not-exist'));
}
示例3: hocwp_setup_theme_pre_get_users
function hocwp_setup_theme_pre_get_users(WP_User_Query $query)
{
if (is_admin()) {
if ($GLOBALS['pagenow'] == 'users.php') {
$user = wp_get_current_user();
$exclude = (array) $query->get('exclude');
$exclude[] = $user->ID;
$exclude = array_unique($exclude);
$query->set('exclude', $exclude);
}
}
return $query;
}