Add custom filtering to DIRECTORY LISTING based on ACF Field


Home Forums Front End PM PRO Add custom filtering to DIRECTORY LISTING based on ACF Field

This topic is: Resolved
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #41514
    evaristo g..daporta
    Participant

    Good Mornig!

    In our WordPress, users have an extra field (with Advanced Custom Fields plugin) named Comitee that associates them to a given post (of custom type).

    How we can can filter users listed on DIRECTORY based on the value of both the role and that given Comitee value?

    I have been trying with fep_directory_arguments filter but can imagine how get the relationship with other users based o that custom field value

    Let’s say, if we have the role_in with this values:

    role__in' =>
    array (
    0 => 'administrator',
    1 => 'delegate',
    ))

    How can force to check a given ACF field for every ‘delegate’ role user, before showing oit on the current directory?

    May be adding meta to the args return array in some way??

    Any hint here would be much appreciated!!

    Thanks in advance!

    #41521
    evaristo g..daporta
    Participant

    Nevermind, i figured it out:

    Solution:

    add_filter( 'fep_directory_arguments', function ($args){
                    $user = wp_get_current_user();
                    $role = $user->roles[0];
                    if( $role == 'delegate'){
                        $meta_query = array();
                        $comitee_post= get_field( 'comitee', 'user_'.$user->ID);
                        $meta_query  = array(
                            'relation' => 'AND',
                            array(
                                'key' => 'comitee',
                                'value' => $comitee_post->ID,
                                'compare' => '='
                            ),
                        );
    
                        $args['meta_query']	=   $meta_query;
                    }
                    return $args;
                }, 99);
    

    Hope it helps anyone!

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

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.