Home › Forums › Add-ons › Flexible Content Field › Filter display by ACF fields
Hi,
On one page on my site, I display the marital situation of my users thanks to a ‘situation’ ACF field added to each ‘user’.
For example, on on page, I used that code to get and display the situation on each user page :
$cellValue = trim(esc_html($userData->situation));
2 possible values for this field are : M
or F
.
My need :
I’d need to filter the display of an editorial page according to the situation
of the current logged in user.
To do that, I just want to add a condition in an existing PHP condition string :
“IF ‘condition A’ && ‘condition B’ && ‘condition C’ are met…”, where ‘condition C’ is the one related to ‘situation’ field.
Could you share me please a synthax example, if, let’s say, I need to filter by value F
situation ? I mean : “&& ‘situation’ of the current logged in user is equal to ‘F'”
I guess there’s no need to add any function or action/hook.
Huge thanks for your help,
Law
What exactly are you fitering? Posts? Other users?
Your question is not clear, need more detail.
Hi,
Sorry for being not clear enough.
I wish to filter posts, and more generally content, according to criteria of the current logged in user :
If he has *this situation*, he can see *this*…
My question is restricted to the criteria situation
(which is an ACF added for each user, filled in at user subscription) :
If the value of the situation
is F
, so the current logged in user can see this…
And in my code, I just need the synthax to add this criteria “situation = F for the current logged in user” (starting with &&...
)
How could I do ?
Thanks a lot,
Kind regards,
Law
You need to use a pre_get_posts filter and set a meta_query based on the value of the field for the logged in user.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.