$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Custom Post Type not showing in Rest API on Multisite|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Custom Post Type not showing in Rest API on Multisite

matteradmin9PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far