Hi,
We’re trying to use your plugin to add a custom taxonomy to our users. But after adding the taxonomy and assigning users to the taxonomy terms, the count always shows 0…
What could be the problem?
Taxonomy code:
register_taxonomy('profession', 'user', array(
'public' =>true,
'single_value' => false,
'show_admin_column' => true,
'labels' =>array(
'name' =>'Professions',
'singular_name' =>'Specialisme',
'menu_name' =>'Specialismes',
'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',
),
'capabilities' => array(
'manage_terms' =>'edit_users',
'edit_terms' =>'edit_users',
'delete_terms' =>'edit_users',
'assign_terms' =>'read',
),
));
When using the below code or viewing the taxonomy in the admin dashboard, it always shows 0 under count…
$terms = get_terms(array(
'taxonomy' => 'profession',
'hide_empty' => false
));
foreach ($terms as $terms) {
echo $terms->name . ": ";
echo $terms->count. "<br>";
}
]]>
Hi
Is there a way to unhook the taxonomies from ‘edit_user_profile’ so they don’t show on frontend profile forms?
I have tried this code I found somewhere else, but haven’t been able to get it to work:
add_action( 'plugins_loaded', function() {
global $lh_uts;
remove_action( 'show_user_profile', array( &$lh_uts, 'user_profile' ) );
remove_action( 'edit_user_profile', array( &$lh_uts, 'user_profile' ) );
});
Many thanks
Steve
Hi
I found an issue with the “Disable Blog” plugin. The custom taxonomy admin page was redirected to the dashboard.
https://www.ads-software.com/plugins/disable-blog/
In order to fix this, there are a couple of filter_hooks to use from Disable Blog plugin:
// Disable redirct
add_filter( 'dwpb_redirect_admin_edit_tags', function( $bool ) {
return false;
}, 10, 1 );
// Disable redirct on specific query
add_filter( 'dwpb_redirect_edit_tax', function( $redirect ) {
if ( isset( $_GET['taxonomy'] ) ) {
return false;
}
return $redirect;
}, 10, 1 );
]]>
We have added custom “client” taxonomy to users. This gives wrong user count for almost all clients on the page /edit-tags.php?taxonomy=client&s=test (where test is the client).
]]>Hello, team. I used a snippet from online to create a user taxonomy which displays the list of the taxonomy terms as a checkbox format. However, I want to display the terms in a dropdown style and must be required to add any user or update the user profile from WordPress. When I use the code below it displays blank where it would display the dropdown.
<?php
// Register Custom Taxonomy
function custom_taxonomy() {
$labels = array(
'name' => _x( 'Departments', 'Departments Name', 'text_domain' ),
'singular_name' => _x( 'Department', 'Department Name', 'text_domain' ),
'menu_name' => __( 'Departments', 'text_domain' ),
'all_items' => __( 'All Departments', 'text_domain' ),
'parent_item' => __( 'Parent Department', 'text_domain' ),
'parent_item_colon' => __( 'Parent Department:', 'text_domain' ),
'new_item_name' => __( 'New Department Name', 'text_domain' ),
'add_new_item' => __( 'Add Department', 'text_domain' ),
'edit_item' => __( 'Edit Department', 'text_domain' ),
'update_item' => __( 'Update Department', 'text_domain' ),
'view_item' => __( 'View Department', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate department with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove departments', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Departments', 'text_domain' ),
'search_items' => __( 'Search Departments', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'no_terms' => __( 'No departments', 'text_domain' ),
'items_list' => __( 'Departments list', 'text_domain' ),
'items_list_navigation' => __( 'Departments list navigation', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'departments', 'user', $args );
}
add_action( 'init', 'custom_taxonomy', 0 );
/**
* Admin page for the 'departments' taxonomy
*/
function cb_add_departments_taxonomy_admin_page() {
$tax = get_taxonomy( 'departments' );
add_users_page(
esc_attr( $tax->labels->menu_name ),
esc_attr( $tax->labels->menu_name ),
$tax->cap->manage_terms,
'edit-tags.php?taxonomy=' . $tax->name
);
}
add_action( 'admin_menu', 'cb_add_departments_taxonomy_admin_page' );
/**
* Unsets the 'posts' column and adds a 'users' column on the manage departments admin page.
*/
function cb_manage_departments_user_column( $columns ) {
unset( $columns['posts'] );
$columns['users'] = __( 'Users' );
return $columns;
}
add_filter( 'manage_edit-departments_columns', 'cb_manage_departments_user_column' );
/**
* @param string $display WP just passes an empty string here.
* @param string $column The name of the custom column.
* @param int $term_id The ID of the term being displayed in the table.
*/
function cb_manage_departments_column( $display, $column, $term_id ) {
if ( 'users' === $column ) {
$term = get_term( $term_id, 'departments' );
echo $term->count;
}
}
add_filter( 'manage_departments_custom_column', 'cb_manage_departments_column', 10, 3 );
/**
* @param object $user The user object currently being edited.
*/
function cb_edit_user_department_section( $user ) {
global $pagenow;
$tax = get_taxonomy( 'departments' );
/* Make sure the user can assign terms of the departments taxonomy before proceeding. */
if ( !current_user_can( $tax->cap->assign_terms ) )
return;
/* Get the terms of the 'departments' taxonomy. */
$terms = get_terms( 'departments', array( 'hide_empty' => false ) ); ?>
<h3><?php _e( 'Departments' ); ?></h3>
<?php }
/*fucntion to display taxonomy terms in a dropdown*/
function cb_taxonomy_select_meta_box($user, $box)
{
$defaults = array('departments' => 'departments');
if (!isset($box['args']) || !is_array($box['args']))
$args = array();
else
$args = $box['args'];
extract(wp_parse_args($args, $defaults), EXTR_SKIP);
$tax = get_taxonomy($departments);
$selected = wp_get_object_terms($user->ID, $departments, array('fields' => 'ids'));
$hierarchical = $tax->hierarchical;
?>
<div id="departments-<?php echo $departments; ?>" class="selectdiv">
<?php
if (current_user_can($tax->cap->edit_terms)):
if ($hierarchical) {
wp_dropdown_categories(array(
'departments' => $departments,
'class' => 'widefat',
'hide_empty' => 0,
'name' => "tax_input[$departments][]",
'selected' => count($selected) >= 1 ? $selected[0] : '',
'orderby' => 'name',
'hierarchical' => 1,
'show_option_all' => " "
));
} else {?>
<select name="<?php echo "tax_input[$departments][]"; ?>" class="widefat">
<option value="0"></option>
<?php foreach (get_terms($departments, array('hide_empty' => false)) as $term): ?>
<option value="<?php echo esc_attr($term->slug); ?>" <?php echo selected($term->term_id, count($selected) >= 1 ? $selected[0] : ''); ?>><?php echo esc_html($term->name); ?></option>
<?php endforeach; ?>
</select>
<?php
}
endif;
?>
</div>
<?php } /*end of code which displays terms in a dropdown on a user edit page*/
add_action( 'show_user_profile', 'cb_edit_user_department_section' );
add_action( 'edit_user_profile', 'cb_edit_user_department_section' );
add_action( 'user_new_form', 'cb_edit_user_department_section' );
/**
* @param int $user_id The ID of the user to save the terms for.
*/
function cb_save_user_department_terms( $user_id ) {
$tax = get_taxonomy( 'departments' );
/* Make sure the current user can edit the user and assign terms before proceeding. */
if ( !current_user_can( 'edit_user', $user_id ) && current_user_can( $tax->cap->assign_terms ) )
return false;
$term = $_POST['departments'];
/* Sets the terms (we're just using a single term) for the user. */
wp_set_object_terms( $user_id, $term, 'departments', false);
clean_object_term_cache( $user_id, 'departments' );
}
add_action( 'personal_options_update', 'cb_save_user_department_terms' );
add_action( 'edit_user_profile_update', 'cb_save_user_department_terms' );
add_action( 'user_register', 'cb_save_user_department_terms' );
/**
* @param string $username The username of the user before registration is complete.
*/
function cb_disable_departments_username( $username ) {
if ( 'departments' === $username )
$username = '';
return $username;
}
add_filter( 'sanitize_user', 'cb_disable_departments_username' );
/**
* Update parent file name to fix the selected menu issue
*/
function cb_change_parent_file($parent_file)
{
global $submenu_file;
if (
isset($_GET['taxonomy']) &&
$_GET['taxonomy'] == 'departments' &&
$submenu_file == 'edit-tags.php?taxonomy=departments'
)
$parent_file = 'users.php';
return $parent_file;
}
add_filter('parent_file', 'cb_change_parent_file');
?>
]]>
Is it possible, to link the “user count” of the tags beeing used to the user page from the “/wp-admin/edit-tags.php?taxonomy=user_tag” page?
Example: A tag for a user is named “test”, then the link on the counter should be “/wp-admin/users.php?user_tag=test”
]]>I have a user profile template, how could I add the taxonomies from the frontend?
]]>hey, this plugin is great!!
thanks.
it does the job. I have been struggling to make it render urls
I have tried a few plugins without luck and diving into stackoverflow with less luck..
like this:
let’s say my user role is instructor.
the taxonomy terms are country and city,
is there any known / good recommended way to have them like this?
https://www.site.com/instructor/country/city/
thanks so much for your kind assistance.
]]>Does this plugin add support for tax_query in pre_get_users?
]]>Very cool plugin, appears to be just about what I need. I used it to create a taxonomy called members, where members can be Regular, student, inactive etc. As my application depends on Javascript and the REST API I added :
‘show_in_rest’ => true,
‘rest_base’ => ‘member’,
and when I access the API at wp-json/wp/v2/member I get a listing with all member types and Id as expected. However I need to list all users of a member type so I was expecting wordpress/wp-json/wp/v2/user/?member=39 would give me a list of users with member id of 39. However it appears to ignore the ?members=39 and just returns all users.
for reference I was looking at: https://jerryjones.dev/2018/03/26/taxonomy-queries-with-wordpress-v2-rest-api/ which has a similar example only for posts.
Is something missing in the /Users endpoint that prevents this from working?
Thanks for the plugin.
Is it posible to restrict a role to only view the users with a taxonomy?
For example: The role of Editor can only see the users with the taxonomy of Artits.
]]>Hello! After updating to WP 5.5.1, the plugin throws a WP error:
Fatal error: Uncaught Error: Call to undefined method stdClass::get_rest_controller() in /www/wp-includes/rest-api.php:2209 Stack trace: #0 /www/wp-includes/rest-api.php(2245): rest_get_route_for_term(Object(WP_Term)) #1 /www/wp-includes/rest-api.php(943): rest_get_queried_resource_route() #2 /www/wp-includes/class-wp-hook.php(285): rest_output_link_header() #3 /www/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(false, Array) #4 /www/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #5 /www/wp-includes/template-loader.php(13): do_action(‘template_redire…’) #6 /www/wp-blog-header.php(19): require_once(‘/Users/spektakl…’) #7 / in /www/wp-includes/rest-api.php on line 2209
09
The site does not throw the error if I deactivate the plugin, but again throws it when activating it.
Maybe it has something to do with “show_in_rest=true” flag that now, with WP 5.5, is needed?
]]>Hi is there a possibility to have this same form on a front end page? Say a logged in user can check a button and call the edit taxonomies directly? (in my case they do not have acces to the profile tab).
Thanks a lot and great job btw.
]]>Hello! Hoping for some help with this one, been around the answer for two days now.
The plugin is great – does any know how to display an author’s Category/taxonomy next to their name on the front end of a post in the template?
For example, you’d have author name and date of post in some templates in the blog. In this case, I want to display author name, their category, and the date.
Any and all help is appreciated!
]]>Hi. I created “position” taxonomy for users and my fields are doctors, teachers and etc. How can I add my custom codes for taxonomies? For example If user position is doctor, show this div, If user position is teacher, show this div
]]>Hi. I created professions taxonomy and created doctors, teachers and etc. How can I get count of doctors, teachers?
]]>Hi,
I’m building some functionality that requires the use of counting the user taxonomy terms.
Am I right in saying that the term count is supposed to update when a user is deleted?
That doesn’t seem to happen at the moment.
To recreate:
Blank installation of WP 5.2.2 and TwentyNinenteen theme.
If I do a quick an dirty edit of its functions php and add the example ‘Professions’ taxonomy registration code into the ‘init’ hook then it will set it up and I can create two terms ‘Prof A’ and ‘Prof B’
Create a new user (subscriber) and assign them to Prof A
Go to Users>Professions and the count for Prof A is 1. – so far so good.
Delete this new user
The Count for Prof A still shows as ‘1’.
Thanks,
Ben
Hi
I have a taxonomy for ‘Specialty’ which reflects the medical speciality of posts on my site, which also used Buddypress. I used Pods to set this up. I want my users to also be able to select the specialty they are qualified in and have this as a searchable taxonomy. The instructions for this plugin have details on registering a new taxonomy, but is it possible to extend this existing taxonomy to users rather than having to set up and maintain a new one?
Thanks
Nicola
Getting terms from some users inexplicably do not show up. I cannot figure out why. I am using the get terms samples below and while this works for the majority of my users I have user accounts with terms assign to them that have absolutely nothing show up. I have even changed $user->ID to the users actual id number and still nothing. I have gone in the database and have confirmed the terms are being recorded and the relationships between the object_id and the term_taxonomy_id exist in the term relationships. In two specific cases my object_id is 8 and 34. I can take the below script, paste it on any page, replace $user->ID with 34 and zero terms are returned. I’d really love some feedback as I am truly perplexed.
echo get_the_term_list( $user->ID, 'service', '<p><span class="label">Services:</span><span class="data">', ', ', '</span></p>' );
or
$terms = get_the_terms( $user->ID, 'service' );
if( ! empty( $terms ) ) :
foreach( $terms as $term ) : ?>
<div class="<?php echo $term->slug; ?>"><?php echo $term->description; ?></div
<?php endforeach;
endif;
]]>
I discovered that terms that were linked to profiles that have been deleted still maintain their relationship. This causes the count to be off and when you sort by the term it displays profiles that are void of content because they no longer exist. Is there a plan to have the plugin remove the relationships if the user is deleted?
]]>Is it possible to limit the visibility of the taxonomy in the user profile based on their user role? I am using the taxonomy to sort the users based on information I control. I would prefer for them to not see or edit this information.
]]>I think LH User Taxonomies is causing erroneous post counts for terms in the taxonomy to which my Users are attached.
Namely, my “company” taxonomy, which is now shared by several Post Types (ie. “Article”, “Viewpoint”) and the Users.
When I try to display the count of a term like $topmost->count
, sadly it is 0.
Trying to fix it with wp_update_term_count_now does NOT successfully update the counts – UNTIL I disable the LH User Taxonomies plugin.
Some kind of conflict going on here?
I’m going to need to fix it, because I would like to have both a User and Post Types utilising said “company” taxonomy at the same time. Is it possible?
Thanks.
]]>I think I have found an issue, and I’m curious whether anyone has solved it…
On a backend User profile edit page…
If a User already has a checked taxonomy term, but I want to uncheck it to have NO value once more, the User profile REFUSES to save with no term value. Instead, it just represents with the same value checked, time and time again.
However, if I CHANGE the checked term value, LH User Taxonomies does accept this and saves the new value.
So, how can I hope to unset a term?
Does this relate to the following portion from line 442… ?
// Removing
} elseif ( 'remove' === $action ) {
$index = array_search( $term, $update_terms );
if ( isset( $update_terms[ $index ] ) ) {
unset( $update_terms[ $index ] );
}
}
Thanks.
]]>https://plugins.trac.www.ads-software.com/browser/lh-user-taxonomies/trunk/lh-user-taxonomies.php#L182
Why did you comment this out? It’s really quite useful for stopping those users from messing with their taxonomy terms.
I have three custom taxonomies registered and values attached to users in the backend.
I’m trying to output those values on user profile pages with no results. Here’s my code with a few debugging things in them
$taxonomies = get_object_taxonomies(get_the_ID(), 'objects');
echo count($taxonomies);
$firm_terms = wp_get_object_terms( get_the_ID(), 'levelofexperience' );
if ( ! empty( $firm_terms ) ) {
if ( ! is_wp_error( $firm_terms ) ) {
foreach( $firm_terms as $term ) {
echo $term->slug;
}
}
}else{
echo "empty";
}
The count() gives 0 – empty array for taxonomies attached to the ID, and the check for empty on one specific tax returns empty. What am I missing here?
]]>Any way to edit the code in order to disable edits by own user, unless the user has a certain role? For example, I want to add a number of taxonomies that can be visible to everyone on their profile page, but only editable by a certain user role.
]]>Hello, I have installed your plugin, added your code but now I am unable to access my site, either through the wordpress dashboard or through FTP.
I get this error message:
Fatal error: Call to a member function add_rewrite_tag() on null in /homepages/1/d413145934/htdocs/The Intelligent Owner/wp-includes/rewrite.php on line 172
Could you please tell me urgently what to do ? This is my business so it is very urgent that I and my user get access back to the site asap. I am not a developer, so please try to give me as much detail as possible on the steps to follow.
Thank you
]]>Hi – Great plugin
I noticed that when I export my users with an export plugin (like in our case I tried Export Users to CSV) id didn’t have the field for our user taxonomy (which we call Industries)
Is there a way, or a plugin that can export this so I can create a report? I’m not as savvy with phpmysql queries – was hoping to find an export user data plugin that would do it.
I do use admin columns pro, and that grabs the field and shows it. It just doesn’t seem to export when I check the csv of users.
Great plugin though!! love it.
Thanks!
Mark
Does this plugin only display associated terms on the front-end or can it be used with WP_User_Query to filter users?
Example:
$args = array
(
'role' => 'member',
'tax_query' => array
(
'relation' => 'OR',
array
(
'taxonomy' => 'colour',
'field' => 'slug',
'terms' => array( 'red' ),
'operator' => 'IN'
)
)
);
]]>
Where I have registered new taxonomy “Topics”, registered to “users”, the “Topics” column displays successfully on the back-end Users list.
But, where a user is attached to multiple terms, those terms do not appear with comma-and-space separation. This makes it hard to distinguish between terms.
See example: https://i.imgur.com/yUvFyNt.png
Am I doing something wrong?
]]>