Skip to content

Instantly share code, notes, and snippets.

@hrsetyono
Last active October 30, 2020 09:57
Show Gist options
  • Save hrsetyono/97e89a1ea732d5661ab1f74a2c23fe9d to your computer and use it in GitHub Desktop.
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
<?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