In your options array use an Array for ‘pages’ value instead string (as your above code)
‘pages’ => array(‘portfolio’, ‘your_cpt_slug‘),
Thanks 🙂 that made it show up on in the right place. But i am getting this :
Cannot modify header information – headers already sent by (output started at /home/zackusa/public_html/responsiveweb.co.za/wp-content/themes/grunge-portfolio/includes/new-meta-boxes.php:2) in /home/zackusa/public_html/responsiveweb.co.za/wp-includes/pluggable.php on line 876
Using the following code
<?php
/**
* Initialize the meta boxes before anything else.
*/
add_action( 'admin_init', '_custom_meta_boxes' );
/**
* Builds the Meta Boxes.
*/
function _custom_meta_boxes() {
$meta_args_array = array(
array(
'id' => 'page_settings',
'title' => 'Page Settings',
'pages' => array( 'page' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'label' => 'Portfolio Type',
'id' => 'portfolio_type',
'type' => 'radio',
'desc' => 'What type of portfolio item is this?',
'choices' => array(
array(
'label' => 'Standard',
'value' => 'standard'
),
array(
'label' => 'Image',
'value' => 'image'
),
array(
'label' => 'Gallery',
'value' => 'gallery'
),
array(
'label' => 'Video',
'value' => 'video'
)
),
'std' => 'standard'
)
)
),
array(
'id' => 'portfolio_settings',
'title' => 'Porftolio Settings',
'pages' => array('portfolio', 'portfolio'),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'label' => 'Video Embed Code',
'id' => 'portfolio_video',
'type' => 'textarea-simple',
'desc' => 'Video Embed Code. The width and height should be: 950px * 385px',
'std' => '',
'rows' => '5'
)
)
)
);
/* load each metabox */
foreach( $meta_args_array as $meta_args ) {
ot_register_meta_box( $meta_args );
}
}
Any suggestions?
Check your new-meta-boxes.php file. Maybe it have some space before <?php
Thanks, I was calling the files in the wrong order. Silly mistake. It all is working now and i have only one final question
This may be really simple but i seem to be stuck on it.
How do i use these meta box fields? When its in option tree i use the get_option_tree(“theid”);
but is there anything i need to do for it to work here? for example if i had a field which gave the option of adding extra text to a place. What code would i use to echo it out?
I have tried get_field() get_option() _custom_meta_boxes() and of course get_option_tree()
Thanks so much for all your help thus far
Most of meta box’s data is saved as post/page metadata so you just simple use: get_post_meta($your_post_id, 'your_field_id')
😀
Worked like a charm! Thank you!
Thanks saved me some time with this too. I was trying to output it the OT way, but they are metadata!