将元对象移动到文章编辑器的最顶端

时间:2021-02-22 作者:Vincenzo Piromalli

我有一个创建自定义元框的函数(使用metabox.io插件),我希望元框保持在标题字段下方的顶部

这是我正在使用的代码

function generator_api() {
    add_meta_box( 
    \'generator_api\', esc_html__( \'Generator\', \'moviewp\' ),
    \'generator_api_form\',
    \'post\',
    \'advanced\',
    \'high\' );
}
function generator_api_form() {
?>
<div class="rwmb-meta-box">
    <div class="rwmb-field rwmb-text-wrapper">
        <div id="Generator" class="postbox rwmb-default">
            <input type="text" id="term" class="textInput" autocomplete="off" placeholder="Search...">
            <div id="major-publishing-actions" style="overflow:hidden">
                <div id="publishing-action" class="fetch-details">
                    <span class="culo">
                        <span id="hideme">
                            <input type="radio" name="test" value="movie" required="" checked="">
                            <span id="film"><?php echo esc_html__( \'Movie\', \'moviewp\' ) ?></span>
                            <input id="TV" type="radio" name="test" value="tv">
                            <span id="TV"><?php echo esc_html__( \'TV\', \'moviewp\' ) ?></span>
                            <span id="movieform">
                                <input title="fetchm" class="rwmb-text" placeholder="IMDb ID" type="text" id="fetchm" name="fetchm" value="">
                                <input type="button" class="button button-primary" id="fetchmovie" name="fetchmovie" value="Movie">
                            </span>
                            <span id="tvform" class="hide">
                                <input title="fetcht" class="rwmb-text" placeholder="TMDB ID" type="text" id="fetcht" name="fetcht" value="">
                                <input type="button" id="fetchtv" class="button button-primary" name="fetchtv" value="TV">
                            </span>
                        </span>
                    </span>
                    <span id="publishme"></span>
                    <span id="api_status">
                        <i class="fa fa-circle rotondo"></i><?php echo esc_html__( \'API is online\', \'moviewp\' ) ?>
                    </span>
                    <div id="message"></div>
                </div>
            </div>
            <ul id="pagination"></ul>
        </div>
    </div>
</div>
<?php
}
add_action( \'add_meta_boxes\', \'generator_api\' );

1 个回复
SO网友:Vincenzo Piromalli

找到解决方案:)

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\']);
});
add_action(\'add_meta_boxes\', \'generator_api\');