Support

Account

Home Forums Add-ons Flexible Content Field Filter display by ACF fields

Solving

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

  • Hi, does my precisions help to see question ?
    Best 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.

  • Hello John,
    Thank you so much, I will try this.
    Law

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.