$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Too many revision when post status is changes|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - Too many revision when post status is changes

matteradmin7PV0评论
This question already has answers here: How to avoid infinite loop in save_post callback (3 answers) Closed 6 years ago.

When ever i update the custom post type it generates too many revision which crashed the website. ( memory exceeded) How can i debug this issue?

Update : I was able to find the culprit. Will it be possible for some one to detect what i did wrong in the below code :

if (class_exists('wpprolister_core')) {

    add_action('wp_insert_post', 'wpprolister_updated_to_publish', 10, 3);

    function wpprolister_updated_to_publish($post_id, $post, $update)
    {

        if (get_field('wpprolister_advanced_option_edit_seo', $post_id)) {

            $metatitle     = get_field('wpprolister_seo_title', $post_id);
            $metadesc      = get_field('wpprolister_seo_meta_description', $post_id);
            $metakeywords  = get_field('wpprolister_seo_keyword', $post_id);
            $content       = get_field('wpprolister_description', $post_id);
            $image         = get_field('wpprolister_listing_slider_image', $post_id);
            $attachment_id = $image['ID'];

            if (!empty($image)):
                $size  = 'medium';
                $thumb = $image['sizes'][$size];
                if (defined('WPSEO_VERSION')) {
                    update_post_meta($post_id, '_yoast_wpseo_title', $metatitle);
                    update_post_meta($post_id, '_yoast_wpseo_metadesc', $metadesc);
                    update_post_meta($post_id, '_yoast_wpseo_focuskw', $metakeywords);}
                //also update the content and featured image
                $my_post = array(
                    'ID'           => $post_id,
                    'post_content' => $content,
                );
                wp_update_post($my_post);
                update_post_meta($post_id, '_thumbnail_id', $attachment_id);

            endif;

        }
    }
}

How i solved the problem (please let me know if i did wrong ):

remove_action('wp_insert_post', 'wpprolister_updated_to_publish');
            $my_post = array(
                'ID'           => $post_id,
                'post_content' => $content,
            );
            wp_update_post($my_post);
            add_action('wp_insert_post', 'wpprolister_updated_to_publish');
This question already has answers here: How to avoid infinite loop in save_post callback (3 answers) Closed 6 years ago.

When ever i update the custom post type it generates too many revision which crashed the website. ( memory exceeded) How can i debug this issue?

Update : I was able to find the culprit. Will it be possible for some one to detect what i did wrong in the below code :

if (class_exists('wpprolister_core')) {

    add_action('wp_insert_post', 'wpprolister_updated_to_publish', 10, 3);

    function wpprolister_updated_to_publish($post_id, $post, $update)
    {

        if (get_field('wpprolister_advanced_option_edit_seo', $post_id)) {

            $metatitle     = get_field('wpprolister_seo_title', $post_id);
            $metadesc      = get_field('wpprolister_seo_meta_description', $post_id);
            $metakeywords  = get_field('wpprolister_seo_keyword', $post_id);
            $content       = get_field('wpprolister_description', $post_id);
            $image         = get_field('wpprolister_listing_slider_image', $post_id);
            $attachment_id = $image['ID'];

            if (!empty($image)):
                $size  = 'medium';
                $thumb = $image['sizes'][$size];
                if (defined('WPSEO_VERSION')) {
                    update_post_meta($post_id, '_yoast_wpseo_title', $metatitle);
                    update_post_meta($post_id, '_yoast_wpseo_metadesc', $metadesc);
                    update_post_meta($post_id, '_yoast_wpseo_focuskw', $metakeywords);}
                //also update the content and featured image
                $my_post = array(
                    'ID'           => $post_id,
                    'post_content' => $content,
                );
                wp_update_post($my_post);
                update_post_meta($post_id, '_thumbnail_id', $attachment_id);

            endif;

        }
    }
}

How i solved the problem (please let me know if i did wrong ):

remove_action('wp_insert_post', 'wpprolister_updated_to_publish');
            $my_post = array(
                'ID'           => $post_id,
                'post_content' => $content,
            );
            wp_update_post($my_post);
            add_action('wp_insert_post', 'wpprolister_updated_to_publish');
Share Improve this question edited Jan 23, 2019 at 18:13 asked Jan 23, 2019 at 14:40 user145078user145078 3
  • 1 Why are you changing the post status so frequently? Maybe there's an alternative to that, without these symptoms? One can also control how many revisions to keep, I guess you've looked into that? – birgire Commented Jan 23, 2019 at 14:52
  • @birgire i not changing the post status , some thing is triggering it..i am not able to find that ,i tried removing revisions but didn't worked out – user145078 Commented Jan 23, 2019 at 15:10
  • @Charles , actually there there is no problem with that ..i was able to find out that some thing is going wrong with wp_update_post($my_post);in the above code. – user145078 Commented Jan 23, 2019 at 18:06
Add a comment  | 

1 Answer 1

Reset to default 0

Maybe you could try looking which functions are hooked to the save_post action and then see what those functions are doing. Perhaps there's some kind of an infinite loop in one of them. Try looking into the global variable $wp_filter, more on that here, How to know what functions are hooked to an action/filter?

Post a comment

comment list (0)

  1. No comments so far