I have a setup where listings are displayed on the site, and I need to filter them based on the user role. Specifically, I want to ensure that only users with the role "Broker" have their listings displayed. If a user is not assigned this role, their listings should not be visible on the front end.
Is there a way to achieve this using Toolset? If so, what would be the best approach to implement this?
Can you please help me understand how should I filter listings on this public page with Access if I need to showcase only listings from the wordpress users in the role Broker, and not show if they are set to Subscriber role for example: hidden link
Same will applies for listing content template: hidden link
What I mean is that WordPress users who belongs to the broker role are allowed to post their own listings, trough designated private dashboard, which was achieved with Access plugin. Sometimes those brokers retire or they do not pay their yearly subscription and they are moved from broker to subscriber role. Subscriber role doesn't allow them to add listings from their designated dashboard, as I said which is achieved with Access plugin.
Now, what I would love to do, if it is possible, when we downgrade them from broker to subscriber role, that listings published from those brokers, now subscribers, are not anymore visible on the website. I would love to do some kind of conditional logic where I can say "do not show listings from user accounts that do not belong to broker role".
There is no such native feature available with Toolset.
In such a case you should try to use the "set_user_role" hook:
add_action('set_user_role','func_update_post_status_after_user_role_update_change',10,3);
function func_update_post_status_after_user_role_update_change($user_id,$role,$old_roles) {
if($role == 'subscriber' and in_array('broker',$old_roles) ) { // or whatever you want
$posts = get_posts('numberposts=-1&author='.$user_id);
foreach($posts as $post) {
/// do what ever you want either delete post or change post status
}
}
}
More info:
=> hidden link
This will reuqire pure custom code which is beyond the scope of our support policy. if you require any help with such custom code, you are welcome to contact any of our certified partners:
- https://toolset.com/contractors/
Just one more clarification, so I can't set rule in the current view (hidden link) that is showcasing only Listings that are belonging to the user role Broker?