dan400o6
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Developing with WordPress
In reply to: Duplicate a post from REST APIOk, so I have a plugin called premium add-ons, it has a feature to duplicate a post exactly how I want, only problem is I can’t do it from the API so I’m trying to add that functionality.
I think if I can pass the post correctly, this plugin will take care of it.
Heres the API route I created, in my functions.php.
add_action( 'rest_api_init', function () { register_rest_route( 'duplicatePost/v1', 'posts/(?P<id>\d+)', array( 'methods' => 'POST', 'callback' => 'duplicate_post', ) ); } );Here is the function I’m trying to pass the request to:
public function duplicate_post(WP_REST_Request $request) { $post = get_post($request['post_id']); $post = sanitize_post( $post, 'db' ); $duplicated_post_id = self::insert_post( $post ); if ( ! is_wp_error( $duplicated_post_id ) ) { self::duplicate_post_taxonomies( $post, $duplicated_post_id ); self::duplicate_post_meta_data( $post, $duplicated_post_id ); } die(); }Forum: Developing with WordPress
In reply to: Error when I try to create post via apiForum: Everything else WordPress
In reply to: Problem with REST API@pluginbuilders I’ve tried that already I should’ve posted that. But I get the same error message regardless with quotes or not.
- This reply was modified 5 years, 3 months ago by dan400o6.
Viewing 3 replies - 1 through 3 (of 3 total)