Home › Forums › General Issues › How to filter products with ACF in rest API › Reply To: How to filter products with ACF in rest API
Previously, I’ve added some code to my functions file:
// Create custom query for API
if( ! function_exists( 'product_meta_request_params' ) ) :
function product_meta_request_params( $args, $request ){
$args += array(
'meta_key' => $request['meta_key'],
'meta_value' => $request['meta_value'],
'meta_query' => $request['meta_query'] == 1 ? array(
array(
"key" => "model",
"value" => array(''),
"compare" => 'NOT IN',
)
) : $request['meta_query']
);
return $args;
}
add_filter( 'rest_product_query', 'product_meta_request_params', 99, 2 );
endif;
My API URL then looked like:
https://www.domain.com/wp-json/wp/v2/product/?page=' . $current_page . '&per_page=10&meta_query=1
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.