I'm using WP Multisite and can't seem to pull through my custom post types via the API.

<?php
function terms_post_type() {
    $labels = array(
        'name'                => _x( 'Policies', 'Post Type General Name', 'name' ),
        'singular_name'       => _x( 'Policy', 'Post Type Singular Name', 'name' ),
        'menu_name'           => __( 'Policies', 'name' ),
        'parent_item_colon'   => __( 'Parent Policy', 'name' ),
        'all_items'           => __( 'All Policies', 'name' ),
        'view_item'           => __( 'View Policy', 'name' ),
        'add_new_item'        => __( 'Add New Policy', 'name' ),
        'add_new'             => __( 'Add New', 'name' ),
        'edit_item'           => __( 'Edit Policy', 'name' ),
        'update_item'         => __( 'Update Policy', 'name' ),
        'search_items'        => __( 'Search Policy', 'name' ),
        'not_found'           => __( 'Not Found', 'name' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'name' ),
    );

    $args = array(
        'label'               => __( 'Policies', 'name' ),
        'description'         => __( 'Terms and Conditions', 'name' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'author', 'revisions', 'custom-fields', 'page-attributes' ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
        'rest_base'           => 'policy',
        'show_in_rest'        => true
    );

    register_post_type( 'policy', $args );
}

add_action( 'init', 'terms_post_type', 1 );

When I then hit http://.localtest.me/wp-json/wp/v2/policy I get:

{
    "code": "rest_no_route",
    "message": "No route was found matching the URL and request method",
    "data": {
        "status": 404
    }
}

Feel like I'm overlooking something.

  • try adding a (mostly unnecessary) comma after the last true – marvinpoo Dec 7 at 14:12
  • Unfortunately I'm still getting the same issue @marvinpoo – Jamie Halvorson Dec 7 at 14:33
  • Hmm, do other REST requests work? – marvinpoo Dec 7 at 14:37
  • 1
    Think there's something in the theme tripping it out, I moved the CPT to a plugin and deactivated the theme and it works fine. When I find out what it is I'll post it back here. – Jamie Halvorson Dec 7 at 15:03
  • 1
    fell free to come back again! I will answer back when I am in the office tomorrow, if noone else can help you. Cheers! – marvinpoo Dec 7 at 15:07

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.