View difference between Paste ID: AfKWHCSE and yPi5RfAa
SHOW: | | - or go back to the newest paste.
1
This is the functions.php from the plugin that creates the CPT and the metaboxes
2
<?php
3
4
/*
5
Plugin Name: Scrutinies Functions
6
*/
7
8
add_action( 'init', 'register_cpt_artist' );
9
10
function register_cpt_artist() {
11
12
    $labels = array( 
13
        'name' => _x( 'Artists', 'artist' ),
14
        'singular_name' => _x( 'Artist', 'artist' ),
15
        'add_new' => _x( 'Add New', 'artist' ),
16
        'add_new_item' => _x( 'Add New Artist', 'artist' ),
17
        'edit_item' => _x( 'Edit Artist', 'artist' ),
18
        'new_item' => _x( 'New Artist', 'artist' ),
19
        'view_item' => _x( 'View Artist', 'artist' ),
20
        'search_items' => _x( 'Search Artists', 'artist' ),
21
        'not_found' => _x( 'No artists found', 'artist' ),
22
        'not_found_in_trash' => _x( 'No artists found in Trash', 'artist' ),
23
        'parent_item_colon' => _x( 'Parent Artist:', 'artist' ),
24
        'menu_name' => _x( 'Artists', 'artist' ),
25
    );
26
27
    $args = array( 
28
        'labels' => $labels,
29
        'hierarchical' => false,
30
        'description' => 'Interviews with Catholic artists.',
31
        'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'trackbacks', 'custom-fields', 'comments' ),
32
        'taxonomies' => array( 'category', 'specialty' ),
33
        'public' => true,
34
        'show_ui' => true,
35
        'show_in_menu' => true,
36-
        
36+
37-
        
37+
38
        'exclude_from_search' => false,
39
        'has_archive' => true,
40
        'query_var' => true,
41
        'can_export' => true,
42
        'rewrite' => true,
43
        'capability_type' => 'post'
44
    );
45
46
    register_post_type( 'artist', $args );
47
}
48
49
function be_sample_metaboxes( $meta_boxes ) {
50
	$prefix = '_cmb_ds_';
51-
/**
51+
52-
 * Either declare the $prefix variable globally here, or else
52+
53-
 * declare it within the function itself (NOT globally).
53+
54-
 *
54+
55-
 * The main reason for a global $prefix variable is if you're creating
55+
56-
 * lots of metaboxes using different functions, and you want to set the 
56+
57-
 * $prefix in just one place.
57+
58-
 */
58+
59-
global $prefix;
59+
60-
$prefix = '_cmb_'; // Prefix for all fields
60+
61
				'desc' => 'Dummy text to see what happens',
62-
	global $prefix;
62+
63
				'type' => 'text'
64
			),
65
		),
66
	);
67
68
	return $meta_boxes;
69
}
70
add_filter( 'cmb_meta_boxes', 'be_sample_metaboxes' );
71
72
// Initialize the metabox class
73
add_action( 'init', 'be_initialize_cmb_meta_boxes', 9999 );
74
function be_initialize_cmb_meta_boxes() {
75
	if ( !class_exists( 'cmb_Meta_Box' ) ) {
76
		require_once( 'lib/metabox/init.php' );
77
	}
78
}
79
80
This is the single-artist.php code:
81
<?php 
82
/* 
83
 * Template Name: Artist 
84
 * This template displays Artist Details 
85
 */ 
86
  
87
remove_action('genesis_after_post_content', 'genesis_post_meta'); //remove post-meta 
88
remove_action('genesis_before_post_content', 'genesis_post_info'); //remove post-info 
89
add_action('genesis_after_post_content', 'child_get_artists_field'); //display meta-box content after the content 
90
91
//Function to show the content 
92
function child_get_artists_field() { 
93
        echo '<strong>Bacon '. genesis_get_custom_field( '_cmb_ds_test_text' ) .'</strong>'; 
94
} 
95
96
genesis(); // requires Genesis 1.3+  
97
?>