duanpen9294 2019-03-29 13:07
浏览 30

Wordpress粘贴邮政复选框不保存

i am working on save only on sticky post .

added this code as plugin .

add_action( 'draft_to_publish', 'only_one_sticky' );
add_action( 'future_to_publish', 'only_one_sticky' );
add_action( 'new_to_publish', 'only_one_sticky' );
add_action( 'pending_to_publish', 'only_one_sticky' );
add_action( 'publish_to_publish', 'only_one_sticky' );

function only_one_sticky( $post_id ) {
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }
    if ( ! wp_is_post_revision( $post_id ) ) {
        $post_id = $post_id->ID;
    }
    $sticky = ( isset( $_POST['sticky'] ) && $_POST['sticky'] == 'sticky' ) || is_sticky( $post_id );
    if( $sticky ) {
        $sticky_posts = array();
        $sticky_posts_list = get_option( 'sticky_posts', array() );

        // The Post IDs are stored in the options table as a single list, so we need to construct a new list with the future posts, plus the newly-published sticky post.
        $new_sticky_posts_list = array();
        foreach ($sticky_posts_list as $sticky_post) {
            $postStatus =  get_post_status ( $sticky_post );
            if ( get_post_status ( $sticky_post ) != 'publish' || $sticky_post == $post_id ) {
                array_push( $new_sticky_posts_list, $sticky_post );
            }
        }
        update_option( 'sticky_posts', $new_sticky_posts_list );
    }
}

i deactivate this plugin .

i notice .

1) created a new post - check stick to front

2) again update same post - stick to front unchecked (removed also from db options sticky_posts )

this happen on every post .


im also using custom theme and wpml plugin

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改