AdvancedCustomFields / AdvancedCustomFields/acf

default values of field not filtrable in REST API wp 6.0, acf - last

Open
#666 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Added a field status with type select.
Set a default value as 'raw'
Set additional values 'html', 'cleared_html'
Added a filter

if( ! function_exists( 'post_meta_request_params' ) ) :
	function post_meta_request_params( $args, $request )
	{
		$args += array(
			'meta_key'   => $request['meta_key'],
			'meta_value' => $request['meta_value'],
			'meta_query' => $request['meta_query'],
		);

	    return $args;
	}
	add_filter( 'rest_post_query', 'post_meta_request_params', 99, 2 );

endif;

create several posts with default status = raw (i can see it in post data) but
wp-json/wp/v2/posts/?meta_key=status&meta_value=raw
giving me []
but if I update the default value manually (on 'raw' again), then filtering happens
this behavior makes the default value less useful and not always obvious in my opinion
Thank you!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the REST request against posts whose select field has the default value raw, then inspect how ACF default values are persisted and how the REST post query handles meta_key and meta_value. Done means posts using the default value are returned by the same filter as posts whose value was manually reset.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.