rest api custom endpoint
-
hi
i have a custom endpoint for creating posts, the post will create successfully and published but won’t send to telegram.
if i use the default endpoint -> POST /wp/v2/posts works fine and sends the post to Telegram.
my Endpoint code is :function mycustom( WP_REST_Request $request ){ $my_post = array( 'post_title' => $request['title'], 'post_content' => $request['content'], 'post_status' => $request['status'], 'post_excerpt' => $request['excerpt'], 'post_author' => 1, 'tax_input' => array( 'category' => $request['category'], 'post_tag' => $request['tags']) ); // Insert the post into the database $pid = wp_insert_post( $my_post ); return "ok"; } add_action( 'rest_api_init', function () { register_rest_route( 'wp/v2', '/mycustom', array( 'methods' => 'POST', 'callback' => 'cpost', ) ); } );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘rest api custom endpoint’ is closed to new replies.