Home › Forums › General Issues › ACF user category and restrict content based on this
Hi guys, I have created a user category (“Sales companies”), and I can assign these to users. What I want is to be able restrict viewing of posts based on this category.
So, a sales company in China can see the products they’re selling, but not products a sales company in Australia is selling, and so on.
I have set this custom field to be displayed on the post edit screen, as well as when adding/editing users.
I need to somehow link the sales company to when a user logs in, but am unsure exactly how to do this.
I added the following to my template to test, and on each post is displays the correct sales company, but its (obviously) not linked to the sales company the user belongs to.
<?php if( get_field(‘sales_companies’) ): ?>
<?php foreach(get_field(‘sales_companies’) as $post_object): ?>
<?php echo the_field(‘sales_companies’) ?>
<?php endforeach; ?>
<?php endif; ?>
If anyone has any direction in which to head with this, it would be much appreciated!
Thanks
Hi @jayseventwo
So the posts are the regular posts in WP? And you want to restrict viewing specific categories of these both in archive, index and single?
Hi Jonathon, yes exactly. So, depending on the sales company, they can only see the posts assigned to their category.
Alright.
While it’s possible to do it requires quite a bit of coding.. You’d need to hook into each archive, single etc. queries and exclude posts based on the users value and posts value. It’s also not really an ACF issue, more of an overall code challenge 😉
If you’re not up for this I’d suggest you either hire a developer to do it for you or take a look at the many membership/post restriction plugins out there.. they might be what you need 🙂
This for example: https://pippinsplugins.com/restricted-content-plugin-free/
If you want I’m able to help you outside of ACF forum as a developer by hourly rate but I’m sure any decent WP developer could help you with this.
The topic ‘ACF user category and restrict content based on this’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.