我想有一个自定义分类法,名为技能。
因此,我想在项目自定义帖子类型和用户之间分配此分类。
我的意思是,我可以在项目自定义帖子类型中选择技能分类(没问题(
我可以在用户配置文件中选择技能分类(主要问题(
谁能帮我?
谢谢
显然,
WP_User_Query
中还没有'tax_query'
的核心实现。
然而,还有另一种使用get_objects_in_term
的方法
$taxonomy = 'skills';
$users = get_objects_in_term( $term_id, $taxonomy );
if(!empty($users)){
// WP_User_Query arguments
$args = array (
'role' => 'teacher',
'order' => 'DESC',
'orderby' => 'user_registered',
'include' => $users
);
// The User Query
$user_query = new WP_User_Query( $args );
// The User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo '<li><span>' . esc_html( $user->skill ) . '</span></li>';
}
}
else {
// number of found
}
}
else {
// no users found
}
或者如果您想为部分和用户添加分类法,请使用下面的代码。
根据您的要求和用户传递帖子类型
函数 my_register_user_taxonomy(( {
register_taxonomy(
'profession',
'user',
array(
'public' => true,
'labels' => array(
'name' => __( 'Professions' ),
'singular_name' => __( 'Profession' ),
'menu_name' => __( 'Professions' ),
'search_items' => __( 'Search Professions' ),
'popular_items' => __( 'Popular Professions' ),
'all_items' => __( 'All Professions' ),
'edit_item' => __( 'Edit Profession' ),
'update_item' => __( 'Update Profession' ),
'add_new_item' => __( 'Add New Profession' ),
'new_item_name' => __( 'New Profession Name' ),
'separate_items_with_commas' => __( 'Separate professions with commas' ),
'add_or_remove_items' => __( 'Add or remove professions' ),
'choose_from_most_used' => __( 'Choose from the most popular professions' ),
),
'rewrite' => array(
'with_front' => true,
'slug' => 'author/profession' // Use 'author' (default WP user slug).
),
'capabilities' => array(
'manage_terms' => 'edit_users', // Using 'edit_users' cap to keep this simple.
'edit_terms' => 'edit_users',
'delete_terms' => 'edit_users',
'assign_terms' => 'read',
),
'update_count_callback' => 'my_update_profession_count' // Use a custom function to update the count.
)
);
}