0

I have custom wordpress post type (job_listing - from WP Job Manager plugin) and add new posts via REST API requests (Postman). The problem is one meta field (geolocation position) in this post becomes visible on the frontend only when I manually open this newely created post and click on 'Update'/'Publish' button. I'm thinking of the function that programmatically simulate this action (click on the Update button) but only once (when the custom post type was created).

function update_job_once_created ( ) {
  save/update this post;
}
add_action( 'save_post_job_listing', 'update_job_once_created' );
Yurii
  • 61
  • 1
  • 7
  • Check this answer - https://stackoverflow.com/questions/46940238/add-post-meta-fields-via-wp-api-v2 – Snuffy Jan 20 '23 at 08:32
  • Ok, thank you for this info. The matter is I already tried 'update_post_meta' function on my imported posts but it doesn't help. I'm able to change programmatically (action in functions.php) meta values of my imported posts but for some reasons they become visible on the map (Jobs Geolocation addon to WP Job Manager) only after I click on the update button. Maybe wordpress by clicking on update button adds some 'labels'/'aliases' to custom post once its created.. – Yurii Jan 20 '23 at 09:39
  • When you create the post do you use this hook rest_insert_(post_type) ? – Snuffy Jan 20 '23 at 09:41
  • I just tried this code (for the custom post type 'job_listing'): add_action("rest_insert_job_listing", function ($post, $request, $creating) { $metas = $request->get_param("meta"); if (is_array($metas)) { foreach ($metas as $key => $value) { update_post_meta($post->ID, $key, $value); } } }, 10, 3); Should I change something here? – Yurii Jan 20 '23 at 09:44
  • This code is placed in functions.php and I export posts via Postman. Am I doing something wrong? – Yurii Jan 20 '23 at 09:47

0 Answers0