• Hi I was trying to do a sample plugin, and i was not able to view the post after publishing it.im getting “Array” displayed in editor after publishing.Please guide me on this.I am adding the code below.

    ‘<?php

    function apt_add_fields_metabox()
    {
    add_meta_box(
    ‘apt_college_fields’,
    __(‘College Fields’),
    ‘apt_college_fields_callback’,
    ‘college’,
    ‘normal’,
    ‘default’
    );
    }

    add_action(‘add_meta_boxes’,’apt_add_fields_metabox’);

    //Display Fields Metabox Content

    function apt_college_fields_callback($post)
    {
    wp_nonce_field(basename(__FILE__),’wp_college_nonce’);
    $apt_college_stored_meta = get_post_meta($post->ID);
    ?>
    <div class=”wrap college-form”>
    <div class=”form-group”>
    <label for=”issue_check”><?php esc_html_e(‘Issue Date Available’,’apt_domain’); ?></label>
    <select name=”issue_check” id=”issue_check”>
    <?php
    $option_value = array(‘Yes’,’No’);
    foreach($option_value as $key => $value)
    {
    if($value == $apt_college_stored_meta[‘issue_check’][0])
    { ?>
    <option selected><?php echo $value; ?></option>
    <?php
    }
    else
    {
    ?>
    <option ><?php echo $value; ?></option>
    <?php

    }
    }
    ?>
    </select>
    </div>

    <div class=”form-group”>
    <label for=”college-details”><?php esc_html_e(‘College Details’,’apt_domain’); ?></label>
    <?php
    $content = get_post_meta($post->ID,’college-details’,true);
    $editor = ‘college-details’;
    $settings = array(
    ‘textarea_rows’ => 5,
    ‘media_buttons’ => true
    );

    wp_editor($content,$editor,$settings);
    ?>
    </div>
    <div class=”form-group”>
    <label for=”application_date”><?php esc_html_e(‘Application Available Date’,’apt_domain’); ?></label>
    <input type=”date” name=”application_date” id=”application_date” value=”<?php if(!empty($apt_college_stored_meta[‘application_date’])) echo esc_attr($apt_college_stored_meta[‘application_date’][0]); ?>” />
    </div>
    </div>
    <?php
    }

    function apt_college_save($post_id)
    {
    $is_autosave = wp_is_post_autosave($post_id);
    $is_revision = wp_is_post_revision($post_id);
    if(isset($_REQUEST[‘wp_college_nonce’]) && wp_verify_nonce($_REQUEST[‘wp_college_nonce’],basename(__FILE__)))
    {
    $is_valid_nonce = true;
    }
    else
    {
    $is_valid_nonce = false;
    }

    if($is_autosave || $is_revision || !$is_valid_nonce)
    {
    return;
    }

    if(isset($_REQUEST[‘issue_check’]))
    {
    update_post_meta($post_id,’issue_check’,sanitize_text_field([‘issue_check’]));
    }

    if(isset($_REQUEST[‘college-details’]))
    {
    update_post_meta($post_id,’college-details’,sanitize_text_field([‘college-details’]));
    }

    if(isset($_REQUEST[‘application_date’]))
    {
    update_post_meta($post_id,’application_date’,sanitize_text_field([‘application_date’]));
    }
    }

    add_action(‘save_post’,’apt_college_save’);
    ?>’

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Post not getting displayed after save’ is closed to new replies.