How to update custom meta fields with rest api?

I Resolved: function job_listings_to_api( $args, $post_type ) { if ( ‘job_listing’ === $post_type ) { $args[‘show_in_rest’] = true; } return $args; } add_filter( ‘register_post_type_args’, ‘job_listings_to_api’, 10, 2 ); add_action( ‘rest_api_init’, ‘create_api_posts_meta_field’ ); function create_api_posts_meta_field() { register_rest_field( ‘job_listing’, ‘_date-start’, array( ‘get_callback’ => ‘get_post_meta_for_api’, ‘update_callback’ => ‘update_post_meta_for_api’, ) ); } function get_post_meta_for_api( $object, $field_name, $request ) { … Read more

Wp Rest Api Custom Endpoint for page subpages

It works.. function list_subpages() { $data = array(); $request = array(); $id = 151; $subpages = get_pages( array( ‘child_of’ => $id, ‘sort_column’ => ‘menu_order’ ) ); if ( empty( $subpages ) ) { return null; } foreach ($subpages as $p) { $data[‘id’] = $p->ID; $data[‘title’] = $p->post_title; $data[‘img’] = wp_get_attachment_url( get_post_thumbnail_id($p->ID) ); $request[] = $data; … Read more

WP Rest API convert permalink to post ID for fetch

The core rewrite API does offer the function url_to_postid() (as mentioned by @stephen-sabatini) which can find a post ID from a URL. However it seems less than ideal to have to make a request up front just to determine the post ID… The REST API does not natively offer the ability to query by date … Read more

rest_post_query on multiple post types?

Define the callback as a named function and hook it separately for each post type. function wpse_299908_order_rest_query( $args ) { $args[‘orderby’] = ‘menu_order’; $args[‘order’] = ‘ASC’; return $args; } add_filter( ‘rest_post_query’, ‘wpse_299908_order_rest_query’ ); add_filter( ‘rest_page_query’, ‘wpse_299908_order_rest_query’ ); There’s no filter that automatically applies to all endpoints, likely for the same reason that you can’t query … Read more