0

Im setting up an endpoint that I want to use to update ACF fields in a custom post type.

Here I register the field endpoint and callback

function wp_api_assign_external_writer() {
  register_rest_route( 'responsify/v1', 'assign_external_writer/', array(
        'methods' => 'POST',
        'callback' => 'assign_external_writer_callback',
    ));
}
function assign_external_writer_callback( $request ) {


$parameters = $request->get_params();
$project_id = $parameters['project_id'];
$writer = $parameters['writer'];

update_field('content_external_writer',$writer,$project_id);

  
}

sending this request in postman: http://localhost:32851/wp-json/responsify/v1/assign_external_writer?writer=32272&project=2527

If I use "title=my_new_title" instead of writer it updates correctly. But using an ACF doesnt update. I read that this should work with update_field but it is not. Am I doing something wrong?

2 Answers 2

1

It looks like you have the variable $project_id defined, but then in your update_field() call you are using a different variable name: $project

update_field('content_external_writer', $writer, $project);

If you change your update_field() call to use $project_id for the $post_id parameter, the update should work:

update_field('content_external_writer', $writer, $project_id);
Sign up to request clarification or add additional context in comments.

1 Comment

thanks but that was just a typo on my part, I was using the correct post param
0

I notice using get_post_meta that a non-nested key for the metafield exists - 'project_type_content_content_external_writer'

so using

seems to work just fine

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.