-
-
Save hrsetyono/97e89a1ea732d5661ab1f74a2c23fe9d to your computer and use it in GitHub Desktop.
https://wptips.dev/custom-rest-api - Snippet from that article to create the custom post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', 'my_post_types' ); | |
function my_post_types() { | |
register_post_type( 'project', [ | |
'public' => true, | |
'label' => 'Project' | |
] ); | |
register_taxonomy( 'project_category', ['project'], [ | |
'hierarchical' => true | |
] ); | |
$has_projects = get_posts(['post_type' => 'project']); | |
// create 2 placeholder projects | |
if( !$has_projects ) { | |
wp_insert_post([ | |
'post_title' => 'Project 1', | |
'post_status' => 'publish', | |
'post_type' => 'project', | |
'post_content' => 'Lorem ipsum dolor sit amet consectetur adipisicing elit.' | |
]); | |
wp_insert_post([ | |
'post_title' => 'Project 2', | |
'post_status' => 'publish', | |
'post_type' => 'project', | |
'post_content' => 'Quibusdam exercitationem ut culpa, tempora ab illum.' | |
]); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment