• Hi All,

    I have a ACF REST API as below –
    [
    {
    “id”: 1206,
    “acf”: {
    “user_id”: {
    “ID”: 11,
    “user_firstname”: “Test”,
    “user_lastname”: “User”,
    “nickname”: “testuser”,
    “user_nicename”: “testuser”,
    “display_name”: “Test User”,
    “user_email”: “[email protected]”,
    “user_url”: “”,
    …………
    },
    “solution_id”: [
    739,
    496
    ],

    }
    }
    ]

    I would like to query based on “user_email” filed inside the User_id object. Something like https://mysite.com/wp-json/acf/v3/[email protected]

    I have below code in my theme function.php file.

    function my_pre_get_posts( $query ) {

    // do not modify queries in the admin
    if( is_admin() ) {
    return $query;
    }

    // only modify queries for ‘event’ post type
    if( isset($query->query_vars[‘post_type’]) && $query->query_vars[‘post_type’] == ‘solutionaccess’ ) {

    // allow the url to alter the query
    if( isset($_GET[‘user_email’]) ) {

    $query->set(‘meta_key’, ‘user_email’);
    $query->set(‘meta_value’, $_GET[‘user_email’]);

    }

    }

    // return
    return $query;

    }
    add_action(‘pre_get_posts’, ‘my_pre_get_posts’);

    This code is not filtering the response. Please suggest

The topic ‘ACF REST API Custom Filter’ is closed to new replies.