• Resolved jockebq

    (@jockebq)


    I think the global $post doesn’t work any longer when using 5.0.3 and Classic Editor.

    I have a custom function which stopped working after my update to 5.0, on 4.9.9 everything works great. I have installed Classic Editor as I have custom made plugins and themes that use this. I have a function which creates a serialized number when the post content is changed so that I can track this via javascript and automatically refresh the page if the content has changed.

    If I create a post on 5.0 with the Classic Editor this function will no longer function. But if I edit a post which was created on 4.9.9 the function will work (with Classic Editor).

    Here is the function:

    function get_post_status_hash() {
        global $post;
        $data = array();
        $args = array(
            'post_type' => 'customposttype',
            'post_status' => 'publish',
            'orderby' => get_post_order(),
        );
        $the_query = new WP_Query($args);
        if ($the_query->have_posts()) : while ( $the_query->have_posts() ) : $the_query->the_post();
            if ( show_post_today( $post->ID ) && show_post_at_this_time( $post->ID ) ) {
                $data[] = $post->ID.":".$post->post_modified;
            }
        endwhile; endif;
        wp_reset_query();
        // Add theme settings
        $data[] = serialize( array(get_theme_mods(), get_widget_data_for_all_sidebars()) );
        return md5(implode(";", $data));
    }

The topic ‘$post not working any more?’ is closed to new replies.