querying to custom field over ACF REST API

[ad_1]

Iam using the “ACF” plugin with “ACF to REST API”. I found a solution for querying a custom field over REST API.

I inserted this into my functions.php:

add_filter( 'rest_{type}_query', function( $args ) {
    $args['meta_query'] = array(
        array(
            'key'   => 'my_field',
            'value' => esc_sql( $_GET['field'] ),
        )
    );

    return $args;
} );

Url: /wp-json/wp/v2/posts?field=test The wildcard {type} can be: post | user | comment | attachment | custom post type | taxonomy

This solution is not perfect. Once this code snipped is added, the filter works but if you go to /v2/{type} <– which usually lists all, this stops working.

Any solution for that?

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer