Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is the functions.php from the plugin that creates the CPT and the metaboxes
- <?php
- /*
- Plugin Name: Scrutinies Functions
- */
- add_action( 'init', 'register_cpt_artist' );
- function register_cpt_artist() {
- $labels = array(
- 'name' => _x( 'Artists', 'artist' ),
- 'singular_name' => _x( 'Artist', 'artist' ),
- 'add_new' => _x( 'Add New', 'artist' ),
- 'add_new_item' => _x( 'Add New Artist', 'artist' ),
- 'edit_item' => _x( 'Edit Artist', 'artist' ),
- 'new_item' => _x( 'New Artist', 'artist' ),
- 'view_item' => _x( 'View Artist', 'artist' ),
- 'search_items' => _x( 'Search Artists', 'artist' ),
- 'not_found' => _x( 'No artists found', 'artist' ),
- 'not_found_in_trash' => _x( 'No artists found in Trash', 'artist' ),
- 'parent_item_colon' => _x( 'Parent Artist:', 'artist' ),
- 'menu_name' => _x( 'Artists', 'artist' ),
- );
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => false,
- 'description' => 'Interviews with Catholic artists.',
- 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'trackbacks', 'custom-fields', 'comments' ),
- 'taxonomies' => array( 'category', 'specialty' ),
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'show_in_nav_menus' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => false,
- 'has_archive' => true,
- 'query_var' => true,
- 'can_export' => true,
- 'rewrite' => true,
- 'capability_type' => 'post'
- );
- register_post_type( 'artist', $args );
- }
- $prefix = '_cmb_'; // Prefix for all fields
- function be_sample_metaboxes( $meta_boxes ) {
- global $prefix;
- $meta_boxes[] = array(
- 'id' => 'test_metabox',
- 'title' => 'Test Metabox',
- 'pages' => array('artist'), // post type
- 'context' => 'normal',
- 'priority' => 'high',
- 'show_names' => true, // Show field names on the left
- 'fields' => array(
- array(
- 'name' => 'Test Text',
- 'desc' => 'Dummy text to see what happens',
- 'id' => $prefix . 'test_text',
- 'type' => 'text'
- ),
- ),
- );
- return $meta_boxes;
- }
- add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' );
- // Initialize the metabox class
- add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
- function be_initialize_cmb_meta_boxes() {
- if ( !class_exists( 'cmb_Meta_Box' ) ) {
- require_once( 'lib/metabox/init.php' );
- }
- }
- This is the single-artist.php code:
- <?php
- /*
- * Template Name: Artist
- * This template displays Artist Details
- */
- remove_action('genesis_after_post_content', 'genesis_post_meta'); //remove post-meta
- remove_action('genesis_before_post_content', 'genesis_post_info'); //remove post-info
- add_action('genesis_after_post_content', 'child_get_artists_field'); //display meta-box content after the content
- //Function to show the content
- function child_get_artists_field() {
- echo '<strong>Bacon'. genesis_get_custom_field('_cmb_test_metabox)') .'</strong>';
- }
- genesis(); // requires Genesis 1.3+
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement