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!
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.
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.