1

What do i want to acheive?
- i want to create a post for my custom post type with the wordpress rest api

What Api route is having problems?
- http://localhost/proftaak/wp-json/wp/v2/mycustomposttype

What http method are you using?
- POST method (post = not working, get = working)

What Local apache server are you using?
- I'm using xampp as local apache + mysql server.

What have i done?
- I created a new custom post type. see here:

add_action('init', 'create_custom_post_types');
add_action('admin_menu', 'remove_default_post_types');

function create_custom_post_types()
{
    // Apparaten (requests)
    register_post_type('apparaten', [
        'public' => true,
        'show_in_rest' => true,
        'label' => 'Apparaten',
        'menu_icon' => 'dashicons-smartphone',
        'capabilities' => array(
            'create_posts' => false
        ),
        'labels' => [
            'singular_name' => 'Apparaat'
        ],
    ]);
}

function remove_default_post_types()
{
    remove_menu_page( 'edit.php' );
    remove_menu_page( 'edit-comments.php' );
}

i've set my custom post type to show_in_rest to true because i want to use it. But if i do a post in postman to the url i get this: enter image description here
i've researched a lot but can't find a solution. any one an idea?

1 Answer 1

1

I found a solution

for custom post types you need to create your own rest api route (wp rest api only adds a GET request). you can do that by using the "register_rest_route" function from wordpress.

Sign up to request clarification or add additional context in comments.

1 Comment

I am new to WordPress, can you please explain the process?

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.