jade99 Posted January 19, 2018 Share Posted January 19, 2018 I'm using this code successfully for one custom post type (CPT). I need to declare multiple CPT's. How do I code this? Additional post types I want to declare: bible3 worship-help library-book /** * Add REST API support to an already registered post type. */ add_action( 'init', 'my_custom_post_type_rest_support', 25 ); function my_custom_post_type_rest_support() { global $wp_post_types; //be sure to set this to the name of your post type! $post_type_name = 'planet'; if( isset( $wp_post_types[ $post_type_name ] ) ) { $wp_post_types[$post_type_name]->show_in_rest = true; $wp_post_types[$post_type_name]->rest_base = $post_type_name; $wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller'; } } Quote Link to comment https://forums.phpfreaks.com/topic/306265-how-to-declare-multiple-custom-post-types-in-code-block-for-rest-api/ Share on other sites More sharing options...
ginerjm Posted January 19, 2018 Share Posted January 19, 2018 Other than have a variable using that name, what the h... IS a 'custom post type'? Quote Link to comment https://forums.phpfreaks.com/topic/306265-how-to-declare-multiple-custom-post-types-in-code-block-for-rest-api/#findComment-1555542 Share on other sites More sharing options...
taquitosensei Posted January 19, 2018 Share Posted January 19, 2018 (edited) Other than have a variable using that name, what the h... IS a 'custom post type'? It's a wordpress post. Not $_POST. Here's the wordpress page on how to register post types. https://codex.wordpress.org/Post_Types Edited January 19, 2018 by taquitosensei Quote Link to comment https://forums.phpfreaks.com/topic/306265-how-to-declare-multiple-custom-post-types-in-code-block-for-rest-api/#findComment-1555563 Share on other sites More sharing options...
ginerjm Posted January 19, 2018 Share Posted January 19, 2018 Once again - a poster should probably mention WORDPRESS when they post in here? Quote Link to comment https://forums.phpfreaks.com/topic/306265-how-to-declare-multiple-custom-post-types-in-code-block-for-rest-api/#findComment-1555576 Share on other sites More sharing options...
maxxd Posted January 22, 2018 Share Posted January 22, 2018 (edited) Use the register_post_type() function for any and all post types you're creating. Make sure 'show_in_rest' is set to true in the arguments to make the data available via the WP rest api. Edited January 22, 2018 by maxxd Quote Link to comment https://forums.phpfreaks.com/topic/306265-how-to-declare-multiple-custom-post-types-in-code-block-for-rest-api/#findComment-1555648 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.