Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Using WordPress 3.7.1 and PHP 5.4.12 I am trying to add a Meta box - text field to my Custom Post Type. My custom Post Type name is "news" and this is my code:

<?php
/* Custom Meta Boxex */
add_action('add_meta_boxes', 'my_cmbox_add');
add_action('save_post', 'save_options');
function my_cmbox_add()
{
    add_meta_box(
        "prodInfo-meta",
        "News Source ",
        "news_source",
        "news",
        "normal",
        "low"
    );
}
function news_source()
{
    global $post;
    $custom = get_post_custom($post->ID);
    $source = $custom['source'][0];

?>
<table>
<tr>
  <td><?php echo '<label>News Source :</label>'; ?></td>
  <td><?php echo '<input name="source" value="'. $source . '" style="width:250px;" />'; ?></td>
</tr>
</table>
<?php
}
function save_options()
{
    global $post;
    if (!isset($_POST['source']) || $post->post_type != 'news')
    {
        return $post;
    }
    update_post_meta($post->ID, "source", $_POST['source']);

}

I am not getting any error but as I said nothing show up in the page. Can you please let me know what I am doing wrong here?

share|improve this question
    
Your code works for me, the only change being to alter the lines that reference the post type to reflect a post type present on my development server. –  s_ha_dum Nov 16 '13 at 2:15
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.