How to add a field in edit post page inside Publish box in Wordpress?

后端 未结 4 1494
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 06:01

I want to add a new checkbox field inside Publish block in add/edit post page. Does anyone have idea how to do that ?

4条回答
  •  滥情空心
    2021-01-30 06:14

    I have finally found the solution. I hope it will be of good use for somebody.

    add_action( 'post_submitbox_misc_actions', 'publish_in_frontpage' );
    function publish_in_frontpage($post)
    {
        $value = get_post_meta($post->ID, '_publish_in_frontpage', true);
        echo '
    ' . '' .'
    '; } function save_postdata($postid) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false; if ( !current_user_can( 'edit_page', $postid ) ) return false; if(empty($postid) || $_POST['post_type'] != 'article' ) return false; if($_POST['action'] == 'editpost'){ delete_post_meta($postid, 'publish_in_frontpage'); } add_post_meta($postid, 'publish_in_frontpage', $_POST['publish_in_frontpage']); }

提交回复
热议问题