admin管理员组

文章数量:1134579

I am building a WordPress plugin the sets the post_parent of a post to the id of a custom post type called series. However, once I click update on the post it successfully updates the post and the next request hangs for 40 seconds on my laptop and never loads on my PC even if I reload or open a new tab. On my PC I have to restart Apache to fix it. Here is relevant the code:

/**
 * Saves part of which series the post is.
 *
 * @param $post_id
 * @param $post
 * @return mixed
 */
function elegant_series_save_post_series_select_meta($post_id, $post) {
    /* Verify the nonce before proceeding. */
    if ( !isset( $_POST['elegant_series_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['elegant_series_meta_box_nonce'], 'save-elegant-series-meta-box' ) ) {
        return $post_id;
    }

    /* Get the post type object. */
    $post_type = get_post_type_object( $post->post_type );

    /* Check if the current user has permission to edit the post. */
    if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
        return $post_id;

    /* Get the posted data and sanitize it for use */
    $series_id = ( isset( $_POST['elegant-series-select-series'] ) ? absint( $_POST['elegant-series-select-series'] ) : '' );

    elegant_series_add_post_to_series($post_id, $series_id);
}

function elegant_series_add_post_to_series($post_id, $series_id)
{
    wp_update_post(
        [
            'ID' => $post_id, 
            'post_parent' => $series_id
        ]
    );
}

could this be due to having a lot of posts - I have about ~2500.

I tried googling various things but did not find anything.

本文标签: pluginsUpdating postparent caused the website to become unresponsive for 40 seconds or more