I’m trying to find a way to block specific users (Not role, users) to certain page of my custom post type into WordPress. (which is using ACF Pro)
I’ve think of using the repeater field, to stock my WP user ID, if a certain box is tick into my CRM, add an entry into the repeater via API.
But my question is, is it a good way of using this field type ?
Cause I have nearly 8K users, growing about 2K per year. everyweek I’ll fill in new entry into the repeater (is there a technical limit for the acf repeater field ?)
So I will have to check if the current user ID is in the repeater field of ACF or not while loading those page with restriction.
Everything I can find on internet use user role, but I can’t use this cause I arbitrary restrict users to some of my custom post type page.
Hope you have a wonderfull day!
Looking up users in a repeater would be extremely inefficient.
I’m not sure I understand what you are trying to block them from.
Specific post types?
If it is blocking them from a specific post I would add a field group that is only available for you to edit on the posts that includes a user field. You would edit the post and select the users that cannot access that page. This would be a more efficient way to check the current user against a list of users.
Thanks for the answer !
so basically I need to restrict specific post consultation (not edition), to specific user.
Nothing related to admin/edition, just be able to see a specific post for a end user.
I was thinking of using ACF to help me doing that (putting user’s ID into a repeater field), but if you said it’s not the right way, I should maybe continue my research on how to do it.
But I want to restrict the post on my web page, nothing related to edition of ACF and/or edit the post, only admin will do that.
Well, setting anything up so that a user cannot view a page would require something in the admin. You need something to specify exactly what users are not allowed to view a page. A user field on each post would allow you to accomplish this without looping over a repeater with a large number of rows because a user field stores all of the user ID’s in a single field.
Thanks for your answer !
I’ve setup a relationship field filtered with my CPT, displayed on the add/edit form of a user.
I can now see this field and select one or multiple page of my CPT for each user.
I will now have to check via PHP if a user have restriction on a specific page.
This field will also be edited via API from my CRM, from what I saw in your documentation, it’s possible.
Is it the good way to go ?
You must be logged in to reply to this topic.
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!