delete_post_meta example


    public function delete_oembed_caches( $post_id ) {
        $post_metas = get_post_custom_keys( $post_id );
        if ( empty( $post_metas ) ) {
            return;
        }

        foreach ( $post_metas as $post_meta_key ) {
            if ( str_starts_with( $post_meta_key, '_oembed_' ) ) {
                delete_post_meta( $post_id$post_meta_key );
            }
        }
    }

    /** * Triggers a caching of all oEmbed results. * * @param int $post_id Post ID to do the caching for. */
    public function cache_oembed( $post_id ) {
        $post = get_post( $post_id );

        
$dismiss_lock      = ! empty( $_POST['dismiss_lock'] );
        $dismiss_autosave  = ! empty( $_POST['dismiss_autosave'] );

        if ( $dismiss_lock ) {
            if ( empty( $changeset_post_id ) && ! $dismiss_autosave ) {
                wp_send_json_error( 'no_changeset_to_dismiss_lock', 404 );
            }
            if ( ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $changeset_post_id ) && ! $dismiss_autosave ) {
                wp_send_json_error( 'cannot_remove_changeset_lock', 403 );
            }

            delete_post_meta( $changeset_post_id, '_edit_lock' );

            if ( ! $dismiss_autosave ) {
                wp_send_json_success( 'changeset_lock_dismissed' );
            }
        }

        if ( $dismiss_autosave ) {
            if ( empty( $changeset_post_id ) || 'auto-draft' === get_post_status( $changeset_post_id ) ) {
                $dismissed = $this->dismiss_user_auto_draft_changesets();
                if ( $dismissed > 0 ) {
                    wp_send_json_success( 'auto_draft_dismissed' );
                }
update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key( $args['menu-item-target'] ) );

    $args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );
    $args['menu-item-xfn']     = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );
    update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] );
    update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );
    update_post_meta( $menu_item_db_id, '_menu_item_url', sanitize_url( $args['menu-item-url'] ) );

    if ( 0 == $menu_id ) {
        update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() );
    } elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) {
        delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' );
    }

    // Update existing menu item. Default is publish status.     if ( $update ) {
        $post['ID']          = $menu_item_db_id;
        $post['post_status'] = ( 'draft' === $args['menu-item-status'] ) ? 'draft' : 'publish';

        $update_post = wp_update_post( $post, true );
        if ( is_wp_error( $update_post ) ) {
            return $update_post;
        }
    }
'ID'          => $post_id,
                    'post_status' => $target_status,
                );
                $post_name     = get_post_meta( $post_id, '_customize_draft_post_name', true );
                if ( $post_name ) {
                    $args['post_name'] = $post_name;
                }

                // Note that wp_publish_post() cannot be used because unique slugs need to be assigned.                 wp_update_post( wp_slash( $args ) );

                delete_post_meta( $post_id, '_customize_draft_post_name' );
            }
        }
    }

    /** * Keeps track of the arguments that are being passed to wp_nav_menu(). * * @since 4.3.0 * * @see wp_nav_menu() * @see WP_Customize_Widgets::filter_dynamic_sidebar_params() * * @param array $args An array containing wp_nav_menu() arguments. * @return array Arguments. */
if ( ! current_user_can( 'edit_theme_options' ) ) {
            wp_send_json_error();
        }

        $attachment_id = absint( $_POST['attachment_id'] );
        if ( $attachment_id < 1 ) {
            wp_send_json_error();
        }

        $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
        delete_post_meta( $attachment_id$key );
        delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );

        wp_send_json_success();
    }

    /** * Updates the last-used postmeta on a header image attachment after saving a new header image via the Customizer. * * @since 3.9.0 * * @param WP_Customize_Manager $wp_customize Customize manager. */
$posts_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );

    foreach ( (array) $posts_to_delete as $post ) {
        $post_id = (int) $post['post_id'];
        if ( ! $post_id ) {
            continue;
        }

        $del_post = get_post( $post_id );

        if ( ! $del_post || 'trash' !== $del_post->post_status ) {
            delete_post_meta( $post_id, '_wp_trash_meta_status' );
            delete_post_meta( $post_id, '_wp_trash_meta_time' );
        } else {
            wp_delete_post( $post_id );
        }
    }

    $comments_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );

    foreach ( (array) $comments_to_delete as $comment ) {
        $comment_id = (int) $comment['comment_id'];
        if ( ! $comment_id ) {
            

    $file = apply_filters( 'update_attached_file', $file$attachment_id );

    $file = _wp_relative_upload_path( $file );
    if ( $file ) {
        return update_post_meta( $attachment_id, '_wp_attached_file', $file );
    } else {
        return delete_post_meta( $attachment_id, '_wp_attached_file' );
    }
}

/** * Returns relative path to an uploaded file. * * The path is relative to the current upload dir. * * @since 2.9.0 * @access private * * @param string $path Full path to the file. * @return string Relative path on success, unchanged path on failure. */
 $old_backup_sizes !== $backup_sizes && ! update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ) ) ) {

        $msg->error = __( 'Cannot save image metadata.' );
        return $msg;
    }

    if ( ! $restored ) {
        $msg->error = __( 'Image metadata is inconsistent.' );
    } else {
        $msg->msg = __( 'Image restored successfully.' );
        if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {
            delete_post_meta( $post_id, '_wp_attachment_backup_sizes' );
        }
    }

    return $msg;
}

/** * Saves image to post, along with enqueued changes * in `$_REQUEST['history']`. * * @since 2.9.0 * * @param int $post_id Attachment post ID. * @return stdClass */

function wp_restore_footnotes_from_revision( $post_id$revision_id ) {
    $footnotes = get_post_meta( $revision_id, 'footnotes', true );

    if ( $footnotes ) {
        update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) );
    } else {
        delete_post_meta( $post_id, 'footnotes' );
    }
}
add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 );

/** * Adds the footnotes field to the revision. * * @since 6.3.0 * * @param array $fields The revision fields. * @return array The revision fields. */
'plugin_name' => $old_data['plugin_name'],
                    'policy_text' => $old_data['policy_text'],
                    'added'       => $old_data['updated'],
                );
                $update_cache = true;
            } else {
                $done[] = $old_data;
            }
        }

        if ( $update_cache ) {
            delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
            // Update the cache.             foreach ( $done as $data ) {
                add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data );
            }
        }
    }

    /** * Checks for updated, added or removed privacy policy information from plugins. * * Caches the current info in post_meta of the policy page. * * @since 4.9.6 * * @return array The privacy policy text/information added by core and plugins. */
$pings = get_posts(
        array(
            'post_type'        => get_post_types(),
            'suppress_filters' => false,
            'nopaging'         => true,
            'meta_key'         => '_pingme',
            'fields'           => 'ids',
        )
    );

    foreach ( $pings as $ping ) {
        delete_post_meta( $ping, '_pingme' );
        pingback( null, $ping );
    }
}

/** * Performs all enclosures. * * @since 5.6.0 */
function do_all_enclosures() {
    $enclosures = get_posts(
        
// If a filename meta exists, use it.     if ( ! empty( $archive_filename ) ) {
        $archive_pathname = $exports_dir . $archive_filename;
    } elseif ( ! empty( $archive_pathname ) ) {
        // If a full path meta exists, use it and create the new meta value.         $archive_filename = basename( $archive_pathname );

        update_post_meta( $request_id, '_export_file_name', $archive_filename );

        // Remove the back-compat meta values.         delete_post_meta( $request_id, '_export_file_url' );
        delete_post_meta( $request_id, '_export_file_path' );
    } else {
        // If there's no filename or full path stored, create a new file.         $archive_filename = $file_basename . '.zip';
        $archive_pathname = $exports_dir . $archive_filename;

        update_post_meta( $request_id, '_export_file_name', $archive_filename );
    }

    $archive_url = $exports_url . $archive_filename;

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