Skip to content

Instantly share code, notes, and snippets.

@hrsetyono

hrsetyono/functions.php Secret

Last active Oct 30, 2020
Embed
What would you like to do?
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