Skip to content

Instantly share code, notes, and snippets.

@ck1125
Last active February 19, 2021 18:38
Show Gist options
  • Save ck1125/4dd362465d333b4a9898c058e3a3e320 to your computer and use it in GitHub Desktop.
Save ck1125/4dd362465d333b4a9898c058e3a3e320 to your computer and use it in GitHub Desktop.
function ap_register_podcast_post_type() {
$labels = array(
'name' => __( 'Podcast Configs', 'newsuk' ),
'singular_name' => __( 'Podcast Config', 'newsuk' ),
'add_new' => __( 'New Podcast Config', 'newsuk' ),
'add_new_item' => __( 'Add New Podcast Config', 'newsuk' ),
'edit_item' => __( 'Edit Podcast Config', 'newsuk' ),
'new_item' => __( 'New Podcast Config', 'newsuk' ),
'view_item' => __( 'View Podcast Config','newsuk' ),
'search_items' => __( 'Search Podcast Configs', 'newsuk'),
'not_found' => __( 'No Podcast Configs Found', 'newsuk' ),
'not_found_in_trash' => __( 'No Podcast Configs found in Trash', 'newsuk' ),
);
$args = array(
'labels' => $labels,
'has_archive' => true,
'public' => true,
'hierarchical' => false,
'supports' => array(
'title',
'custom-fields',
'thumbnail',
'page-attributes'
),
'taxonomies' => array('category'),
'rewrite' => array( 'slug' => 'podcast-config' ),
'show_in_rest' => true
);
register_post_type( 'wd-podcast-config', $args );
$string_meta_arg = array(
'type' => 'string', // Validate and sanitize the meta value as a string.
'description' => 'A meta key associated with a string meta value.', // Shown in the schema for the meta key.
'single' => true, // Return a single value of the type. Default: false.
'show_in_rest' => true, // Show in the WP REST API response. Default: false.
);
$numeric_meta_arg = array(
'type' => 'number', // Validate and sanitize the meta value as a string.
'description' => 'A meta key associated with a string meta value.', // Shown in the schema for the meta key.
'single' => true, // Return a single value of the type. Default: false.
'show_in_rest' => true, // Show in the WP REST API response. Default: false.
);
register_meta( 'post', 'podcast_feed_url', $string_meta_arg);
register_meta( 'post', 'display_sequence_number', $numeric_meta_arg);
}
add_action( 'init', 'ap_register_podcast_post_type' );
//add custom column
add_action( 'manage_wd-podcast-config_posts_custom_column' , 'custom_podcast_config_column', 10, 2 );
add_filter( 'manage_wd-podcast-config_posts_columns', 'set_podcast_config_columns' );
//add custom sortable column
add_filter( 'manage_edit-wd-podcast-config_sortable_columns', 'set_podcast_config_columns' );
function set_podcast_config_columns($columns) {
$columns['display_sequence_number'] = __( 'Display Sequence', 'newsuk' );
return $columns;
}
function custom_podcast_config_column( $column, $post_id ) {
switch ( $column ) {
case 'display_sequence_number' :
echo get_post_meta( $post_id , 'display_sequence_number' , true );
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment