Hi there, so I’m trying get make to create a new post for my wordpress site. My issue is that I need it to create a new post type that my theme made called “Portfolio”. I did some research and found this snippet attached below from this post stating to add this to your Rest API. I’m still a bit of a newbie at this stuff, and I remember setting up the Rest API when I started my Make.com automation. I googled how to modify my Rest API and where to past this code, but I can’t figure it out. I need the beginner steps if anyone knows them.
I’ve tried installing the Code Snippet plugin and pasting it as a PHP Snippet with the modifications to change “book” to “portfolio” However when I go back to make.com’s automation I can’t get the create a post to recognize or find the post type “portfolio”.
Anyone know what steps I’m missing?
/**
* Add REST API support to an already registered post type.
*/
add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );
function my_post_type_args( $args, $post_type ) {
if ( 'book' === $post_type ) {
$args['show_in_rest'] = true;
// Optionally customize the rest_base or rest_controller_class
$args['rest_base'] = 'books';
$args['rest_controller_class'] = 'WP_REST_Posts_Controller';
}
return $args;
}
replace "books" for you custom post type```
I am also trying to do the same, I need a google sheet to create a wordpress post from a custom post I have created. i’m spending today looking into it. if I find out how, I will let you know.
create a custom post type for books using the register_post_type function. Instead of using a filter
// Register a custom post type for books
function my_custom_book_post_type() {
$labels = array(
‘name’ => ‘Books’,
‘singular_name’ => ‘Book’,
‘menu_name’ => ‘Books’,
‘add_new’ => ‘Add New’,
‘add_new_item’ => ‘Add New Book’,
‘edit_item’ => ‘Edit Book’,
‘new_item’ => ‘New Book’,
‘view_item’ => ‘View Book’,
‘search_items’ => ‘Search Books’,
‘not_found’ => ‘No books found’,
‘not_found_in_trash’ => ‘No books found in Trash’,
);
//We’ve created a custom post type called “Books.”
The post type supports a title, editor, and thumbnail.
It has a custom slug of “books” for its URL.
The REST API support is enabled with show_in_rest set to true.