Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress sticky post复选框未保存_Php_Wordpress_Wordpress Theming - Fatal编程技术网

Php Wordpress sticky post复选框未保存

Php Wordpress sticky post复选框未保存,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我正在努力节省只有在粘帖 添加此代码作为插件 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( 'p

我正在努力节省只有在粘帖

添加此代码作为插件

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

我停用了这个插件

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 );
    }
}
我注意到了

1) 创建了一个新的后检查坚持到前面

2) 再次更新同一帖子-未选中粘贴到前面(也从db选项粘贴帖子中删除)

这在每一个帖子上都会发生


im还使用自定义主题和wpml插件