Support

Account

Home Forums ACF PRO ACF Relationship queries with WP Rest API

Unread

ACF Relationship queries with WP Rest API

  • I’m attempting to query by an ACF relationship using the WP Rest API and was having some odd results. So with my setup I would expect the following to return results however nothing is returned.

    /wp-json/wp/v2/custom-post-type/?filter[posts_per_page]=-1&filter[order]=DESC&filter[meta_query][0][key]=website&filter[meta_query][0][value]=1334

    The odd thing is when I do what’s directly in the database for the value, I get results. See the following.

    /wp-json/wp/v2/custom-post-type/?filter[posts_per_page]=-1&filter[order]=DESC&filter[meta_query][0][key]=website&filter[meta_query][0][value]=a:1:{i:0;s:4:"1334";}

    FYI, to get this far I did need to expose the meta_query as it’s not typically usable in public queries. That was done by adding the following to my functions.php file.

    add_filter( 'rest_query_vars', 'test_query_vars' );
    function test_query_vars ( $vars ) {
        $vars[] = 'meta_query';
        return $vars;
    }
Viewing 1 post (of 1 total)

The topic ‘ACF Relationship queries with WP Rest API’ is closed to new replies.