clean_post_cache example


function set_post_type( $post_id = 0, $post_type = 'post' ) {
    global $wpdb;

    $post_type = sanitize_post_field( 'post_type', $post_type$post_id, 'db' );
    $return    = $wpdb->update( $wpdb->posts, array( 'post_type' => $post_type ), array( 'ID' => $post_id ) );

    clean_post_cache( $post_id );

    return $return;
}

/** * Determines whether a post type is considered "viewable". * * For built-in post types such as posts and pages, the 'public' value will be evaluated. * For all others, the 'publicly_queryable' value will be used. * * @since 4.4.0 * @since 4.5.0 Added the ability to pass a post type name in addition to object. * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object. * @since 5.9.0 Added `is_post_type_viewable` hook to filter the result. * * @param string|WP_Post_Type $post_type Post type name or object. * @return bool Whether the post type should be considered viewable. */

    $new = apply_filters( 'pre_wp_update_comment_count_now', null, $old$post_id );

    if ( is_null( $new ) ) {
        $new = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id ) );
    } else {
        $new = (int) $new;
    }

    $wpdb->update( $wpdb->posts, array( 'comment_count' => $new ), array( 'ID' => $post_id ) );

    clean_post_cache( $post );

    /** * Fires immediately after a post's comment count is updated in the database. * * @since 2.3.0 * * @param int $post_id Post ID. * @param int $new The new comment count. * @param int $old The old comment count. */
    do_action( 'wp_update_comment_count', $post_id$new$old );

    

function clean_page_cache( $id ) {
    _deprecated_function( __FUNCTION__, '3.4.0', 'clean_post_cache()' );

    clean_post_cache( $id );
}

/** * Retrieve nonce action "Are you sure" message. * * Deprecated in 3.4.1 and 3.5.0. Backported to 3.3.3. * * @since 2.0.4 * @deprecated 3.4.1 Use wp_nonce_ays() * @see wp_nonce_ays() * * @param string $action Nonce action. * @return string Are you sure message. */


    foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) {
        if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) {
            continue;
        }
        $wpdb->update(
            $wpdb->posts,
            $post_args,
            array( 'ID' => $post_id )
        );
        clean_post_cache( $post_id );
    }
}

/** * Creates the initial theme features when the 'setup_theme' action is fired. * * See {@see 'setup_theme'}. * * @since 5.5.0 * @since 6.0.1 The `block-templates` feature was added. */


        /** This action is documented in wp-includes/post.php */
        do_action( 'wp_trash_post', $post_id );

        add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
        add_post_meta( $post_id, '_wp_trash_meta_time', time() );

        $old_status = $post->post_status;
        $new_status = 'trash';
        $wpdb->update( $wpdb->posts, array( 'post_status' => $new_status ), array( 'ID' => $post->ID ) );
        clean_post_cache( $post->ID );

        $post->post_status = $new_status;
        wp_transition_post_status( $new_status$old_status$post );

        /** This action is documented in wp-includes/post.php */
        do_action( "edit_post_{$post->post_type}", $post->ID, $post );

        /** This action is documented in wp-includes/post.php */
        do_action( 'edit_post', $post->ID, $post );

        /** This action is documented in wp-includes/post.php */
        

        if ( empty( $_REQUEST['s'] ) ) {
            $top_level_pages = array();
            $children_pages  = array();

            foreach ( $pages as $page ) {
                // Catch and repair bad pages.                 if ( $page->post_parent === $page->ID ) {
                    $page->post_parent = 0;
                    $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
                    clean_post_cache( $page );
                }

                if ( $page->post_parent > 0 ) {
                    $children_pages[ $page->post_parent ][] = $page;
                } else {
                    $top_level_pages[] = $page;
                }
            }

            $pages = &$top_level_pages;
        }

        
if ( $link_ids ) {
            foreach ( $link_ids as $link_id ) {
                wp_delete_link( $link_id );
            }
        }
    } else {
        $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
        $wpdb->update( $wpdb->posts, array( 'post_author' => $reassign ), array( 'post_author' => $id ) );
        if ( ! empty( $post_ids ) ) {
            foreach ( $post_ids as $post_id ) {
                clean_post_cache( $post_id );
            }
        }
        $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
        $wpdb->update( $wpdb->links, array( 'link_owner' => $reassign ), array( 'link_owner' => $id ) );
        if ( ! empty( $link_ids ) ) {
            foreach ( $link_ids as $link_id ) {
                clean_bookmark_cache( $link_id );
            }
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.