Home › Forums › Front-end Issues › Create permissions rules with ACF repeater field
Hi,
I’m trying to create a set of permission rules for a custom post type depending on user infos but I don’t see how to wp query my posts with theses infos.
I’ve created a repeater field which allow me to select:
– The user_meta key
– The comparison operator (AND or OR)
– The value of the user_meta key
Here is a screenshot to show you how I’ve done it:
https://cloudup.com/cQ6ohlU895w (the main box is for OR permission and each box in it for AND permissions)
Now I wanted to query my posts if the rules matched or if there is the repeater field is empty but I can’t get my head around it…
Here is an exemple of what the repeater field returns:
Array
(
[0] => Array
(
[ressource_regles_et] => Array
(
[0] => Array
(
[ressource_permission_name] => le-centre
[ressource_permission_rule] => is
[ressource_permission_value_fonction] => Array
(
)
[ressource_permission_value_service] => Array
(
)
[ressource_permission_value_centre] => baudricourt
)
[1] => Array
(
[ressource_permission_name] => le-centre
[ressource_permission_rule] => is
[ressource_permission_value_fonction] => Array
(
)
[ressource_permission_value_service] => Array
(
)
[ressource_permission_value_centre] => curial
)
)
)
[1] => Array
(
[ressource_regles_et] => Array
(
[0] => Array
(
[ressource_permission_name] => la-fonction
[ressource_permission_rule] => is-not
[ressource_permission_value_fonction] => president-e
[ressource_permission_value_service] => Array
(
)
[ressource_permission_value_centre] => Array
(
)
)
)
)
)
Each key indexed first level array is for an OR permission and each array inside [ressource_regles_et]
is for and AND permission.
Now I know how to apply my rules after having queried all the posts but I’d like to get the rules in WP_Query
so that I can use WordPress builtin pagination system.
Any ideas on how to you would do this?
Thanks for your help!
Hi Pipo,
ACF store the subfield data in a very particulary way and it’s hard to use it directly on query but there is a filter provided by ACF to use subfield as meta-queries for WP_query here.
But I suggest to you to use the John Huebner method to adapt and save your repeater as an array Metadata.
It will be more efficient I think.
Hi Feyfey,
The John Huebner method looks like the only viable option in my opinion (and I’ve read a lot of topics on the subject).
Thanks a lot for this wonderful piece of information!
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!
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.