2

I've a custom field what I want to put after the post title input.

How can alter the order or include the custom field before editor?

Here is my code:

function info_posts() {
    add_meta_box(
        'intro_post',               // $id
        'Introducción al post',     // $title
        'meta_info',                // $callback
        'post',                     // $page
        'normal',                   // $context
        'high');                    // $priority
}
add_action('add_meta_boxes', 'info_posts');

function meta_info() {
    global $post;  
    $meta = get_post_meta($post->ID, 'intro_post', true);
    echo '<input type="hidden" name="info_post" value="'.wp_create_nonce(basename(__FILE__)).'" />';  
    echo '<table class="form-table">';           
        echo '<tr>
        <td>
        <strong>Recomendado:</strong><span class="description"> Ingresar hasta 52 palabras / 400 caracteres.</span><br/>
        Total ingresado: '.str_word_count(get_post_meta($post->ID, 'intro_post', true) ).' palabras <span class="description"> (se actualiza al guardar)</span>.<br/><br/>
        <textarea name="intro_post" id="intro_post" cols="95" rows="8">'.$meta.'</textarea><br/><br/>
            <strong>Pequeños tips:</strong> <br/>
                - Cada 25 palabras, añade uno o dos saltos de línea, ingresando el siguiente código: <input onclick="select()" value="<br/><br/>" size="7" style="border-radius:3px;border:1px solid #dcdcdc;background:#eee;color:#444"><br/>
                - El texto será ubicado a la izquierda de la imagen destacada del post, procura detallar lo mejor posible el mismo.
        </td>
            </tr>';
    echo '</table>';
}
function guardar_intro($post_id) {   
    if (!wp_verify_nonce($_POST['info_post'], basename(__FILE__)))
        return $post_id;

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;

    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;
    }  

    $old = get_post_meta($post_id, "intro_post", true);
    $new = $_POST["intro_post"];

    if ($new && $new != $old) {
        update_post_meta($post_id, "intro_post", $new);
    } elseif ('' == $new && $old) {
        delete_post_meta($post_id, "intro_post", $old);
    }
}
add_action('save_post', 'guardar_intro');

What I like to do.

enter image description here

Can help me?

Thanks.

1 Answer 1

2

I just find the solution.

Here is: https://wordpress.stackexchange.com/questions/36600/how-can-i-put-a-custom-meta-box-above-the-editor-but-below-the-title-section-on/88103#88103

The code:

// Move all "advanced" metaboxes above the default editor
add_action('edit_form_after_title', function() {
    global $post, $wp_meta_boxes;
    do_meta_boxes(get_current_screen(), 'advanced', $post);
    unset($wp_meta_boxes[get_post_type($post)]['advanced']);
});

Thank you anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.