1

I have mutli input fields in custom metabox.However, only 2-3 array items show on page, others doesnt seem.For example, "text-ruby" shows but "textname" doesnt show.Why? What is the difference between them? How to fix it?

array(
            'name' => 'Additional Post Title on thumbnail',
            'desc' => 'The text will shown on post thumbnail via our elementor post widget',
            'id' => $prefix . 'text-ruby',
            'type' => 'text',
            'std' => 'You must read this! ;)'
        ),
        array(
            'name' => 'Name',
            'desc' => 'You should write name here',
            'id' => $prefix . 'textname',
            'type' => 'text',
            'std' => 'John Smith.'
        ),

<?php echo get_post_meta(get_the_ID(), 'ozellikler_textname', true); ?>
<?php echo get_post_meta(get_the_ID(), 'ozellikler_text-ruby', true); ?>

EDİT:

full code

it is from theme function.php:

$prefix = 'ozellikler_';

$meta_box = array(
    'id' => 'my-meta-box',
    'title' => 'Post Additional Information Settings - Meta Box',
    'page' => array('post','page','html5-blank'),
    'context' => 'normal',
    'priority' => 'high',
    'fields' => array(
        array(
            'name' => 'Country Flag',
            'desc' => 'The alpha-2 country code for the flag you wish to display. See the full list <a href="https://www.iban.com/country-codes" target="_blank">here.</a>',
            'id' => $prefix . 'text',
            'type' => 'text',
            'std' => 'tr'
        ),
        array(
            'name' => 'Additional Post Title on thumbnail',
            'desc' => 'The text will shown on post thumbnail via our elementor post widget',
            'id' => $prefix . 'text-ruby',
            'type' => 'text',
            'std' => 'You must read this! ;)'
        ),
        array(
            'name' => 'Name',
            'desc' => 'You should write name here',
            'id' => $prefix . 'textname',
            'type' => 'text',
            'std' => 'John Smith.'
        ),
        array(
            'name' => 'Title',
            'desc' => 'You should write Title here',
            'id' => $prefix . 'text-title',
            'type' => 'text',
            'std' => '- Cardiologist & Surgeon'
        ),
        array(
            'name' => 'Profession',
            'desc' => 'You should write Profession here',
            'id' => $prefix . 'text-profession',
            'type' => 'text',
            'std' => 'Tempora impedit pariatur sapiente sit distinctio.'
        ),
        array(
            'name' => 'Graduation',
            'desc' => 'You should write Graduation here',
            'id' => $prefix . 'text-graduation',
            'type' => 'text',
            'std' => 'PhD in Your Choosen Department & Choosen University 1990.'
        ),
        array(
            'name' => 'Experience',
            'desc' => 'You should write Experience here',
            'id' => $prefix . 'text-experience',
            'type' => 'text',
            'std' => '18 Year Working experience in The Hekim\'s Choosen Company.'
        ),
        array(
            'name' => 'Address',
            'desc' => 'You should write Address here',
            'id' => $prefix . 'text-address',
            'type' => 'text',
            'std' => 'Victoria 8007 Australia Envato HQ 121 King Street, Melbourne.'
        ),
        array(
            'name' => 'Phone',
            'desc' => 'You should write Phone here',
            'id' => $prefix . 'text-phone',
            'type' => 'text',
            'std' => '+61 3 8376 6284.'
        ),
        array(
            'name' => 'Mail',
            'desc' => 'You should write Mail here',
            'id' => $prefix . 'text-mail',
            'type' => 'text',
            'std' => 'henryJones@hotmail.com'
        ),
        array(
            'name' => 'Fax',
            'desc' => 'You should write Fax here',
            'id' => $prefix . 'text-fax',
            'type' => 'text',
            'std' => '865461245.'
        ),
        array(
            'name' => 'Member Description',
            'desc' => 'You should write Member Description here',
            'id' => $prefix . 'textarea-member-description',
            'type' => 'textarea',
            'std' => 'On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain.

This is Our Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste commodi animi, totam earum harum quibusdam dolor dolore magnam! Temporibus laborum quas sint. Beatae eos odit doloremque repellendus sequi libero vero, eius excepturi, est deleniti dignissimos totam earum iste rerum atque ut voluptatem soluta officiis, necessitatibus. Sapiente doloribus, suscipit inventore sit.

This is Our Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste commodi animi, totam earum harum quibusdam dolor dolore magnam! Temporibus laborum quas sint.'
        ),
        array(
            'name' => 'Facebook',
            'desc' => 'You should write facebook link here',
            'id' => $prefix . 'text-facebook',
            'type' => 'text',
            'std' => 'https://www.facebook.com/britneyspears'
        ),
        array(
            'name' => 'Twitter',
            'desc' => 'You should write twitter link here',
            'id' => $prefix . 'text-twitter',
            'type' => 'text',
            'std' => 'https://twitter.com/britneyspears'
        ),
        array(
            'name' => 'Pinterest',
            'desc' => 'You should write pinterest link here',
            'id' => $prefix . 'text-pinterest',
            'type' => 'text',
            'std' => 'https://tr.pinterest.com/mm1366295/britney-spears/'
        ),
        array(
            'name' => 'Instagram',
            'desc' => 'You should write Instagram link here',
            'id' => $prefix . 'text-instagram',
            'type' => 'text',
            'std' => 'https://www.instagram.com/britneyspears/?hl=tr'
        ),
        array(
            'name' => 'Skype',
            'desc' => 'You should write Skype account here',
            'id' => $prefix . 'text-skype',
            'type' => 'text',
            'std' => 'sani-ul-hasssan'
        ),
        array(
            'name' => 'E-mail',
            'desc' => 'You should write E-mail here',
            'id' => $prefix . 'email',
            'type' => 'text',
            'std' => '3@gmail.com'
        ),
        array(
            'name' => 'Additional Post Description while hover thumbnail',
            'desc' => 'The text will shown on post thumbnail via our elementor post widget',
            'id' => $prefix . 'textarea',
            'type' => 'textarea',
            'std' => 'Its amazing story so I dont know where must I start to tell...'
        )
    )
);

add_action('admin_menu', 'html5blank_mytheme_add_box');

// Add meta box
function html5blank_mytheme_add_box() {
    global $meta_box;

    add_meta_box($meta_box['id'], $meta_box['title'], 'html5blank_mytheme_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']);
}

// Callback function to show fields in meta box
function html5blank_mytheme_show_box() {
    global $meta_box, $post;

    // Use nonce for verification
    echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';

    echo '<table class="form-table">';

    foreach ($meta_box['fields'] as $field) {
        // get current post meta data
        $meta = get_post_meta($post->ID, $field['id'], true);

        echo '<tr>',
        '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
        '<td>';
        switch ($field['type']) {
            case 'text':
                echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',
                '<br />', $field['desc'];
                break;
            case 'textarea':
                echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',
                '<br />', $field['desc'];
                break;
            case 'checkbox':
                echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
                break;
        }
        echo '<td>',
        '</tr>';
    }

    echo '</table>';
}

add_action('save_post', 'html5blank_mytheme_save_data');

// Save data from meta box
function html5blank_mytheme_save_data($post_id) {
    global $meta_box;

    // verify nonce
    //if (!wp_verify_nonce($_POST['mytheme_meta_box_nonce'], basename(__FILE__))) {
    //    return $post_id;
    //}

    if (
        // Bail if the nonce is empty.
        empty( $_POST['mytheme_meta_box_nonce'] ) ||
        // .. or that it has expired.
        ! wp_verify_nonce( $_POST['mytheme_meta_box_nonce'], basename( __FILE__ ) )
    )
    {
        return $post_id;
    }




    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }

    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } elseif (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }

    foreach ($meta_box['fields'] as $field) {
        $old = get_post_meta($post_id, $field['id'], true);
        $new = $_POST[$field['id']];

        if ($new && $new != $old) {
            update_post_meta($post_id, $field['id'], $new);
        } elseif ('' == $new && $old) {
            delete_post_meta($post_id, $field['id'], $old);
        }
    }
}

it is from my custom plugin :

 <?php

            $query = new \WP_Query($args);
            if ($query->have_posts()) {
                while ($query->have_posts()) {
                    $query->the_post();

?>

<li><a href="<?php echo get_post_meta(get_the_ID(), 'ozellikler_text-facebook', true); ?>"><i class="fa fa-facebook"></i></a></li>
                                    <li><a href="<?php echo get_post_meta(get_the_ID(), 'ozellikler_text-twitter', true); ?>"><i class="fa fa-twitter"></i></a></li>
                                    <li><a href="<?php echo get_post_meta(get_the_ID(), 'ozellikler_text-pinterest', true); ?>"><i class="fa fa-pinterest"></i></a></li>
                                    <li><a href="<?php echo get_post_meta(get_the_ID(), 'ozellikler_text-instagram', true); ?>"><i class="fa fa-instagram"></i></a></li>
                                    <li><a href="mailto:<?php echo get_post_meta(get_the_ID(), 'ozellikler_text-mail', true); ?>"><i class="fa fa-envelope"></i> Email</a></li>
                                </ul>
                            </div>
                        </div>
                        <div class="team-details text-left">
                            <h3 class="member-name"><?php echo get_post_meta(get_the_ID(), 'ozellikler_textname', true); ?></h3>
                            <h5 class="member-post"><?php echo get_post_meta(get_the_ID(), 'ozellikler_text-title', true); ?></h5>
                            <p><?php echo get_post_meta(get_the_ID(), 'ozellikler_textarea', true); ?></p>
                            <?php echo get_post_meta(get_the_ID(), 'ozellikler_text-ruby', true); ?>
  • I think we would need to see the full code. I'm assuming you're looping the given array to generate input boxes but it's a little unclear. What specifically "doesn't show"? The values on save or the textboxes themselves or?... If you could edit your question with further detail that may help future readers address your question. – Howdy_McGee Apr 22 at 22:26
  • @Howdy_McGee I added full code.can you look at again? – I dont believe you Apr 22 at 22:46
  • Have you enable debugging to see if there's any PHP errors that trigger in this file? – Howdy_McGee Apr 22 at 22:53
  • @Howdy_McGee I enabled them, but there is no log file – I dont believe you Apr 22 at 23:21
  • Are they saving to the database properly? Can you flag all the one's that are not saving or that are giving you problems by putting a //comment after each one of the field arrays? – Tony Djukic Apr 23 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.