get_post_meta example



    if ( ! empty( $post->post_password ) ) {
        $post_states['protected'] = _x( 'Password protected', 'post status' );
    }

    if ( 'private' === $post->post_status && 'private' !== $post_status ) {
        $post_states['private'] = _x( 'Private', 'post status' );
    }

    if ( 'draft' === $post->post_status ) {
        if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
            $post_states[] = __( 'Customization Draft' );
        } elseif ( 'draft' !== $post_status ) {
            $post_states['draft'] = _x( 'Draft', 'post status' );
        }
    } elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
        $post_states[] = _x( 'Customization Draft', 'post status' );
    }

    if ( 'pending' === $post->post_status && 'pending' !== $post_status ) {
        $post_states['pending'] = _x( 'Pending', 'post status' );
    }

    
update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );

                        wp_update_post( $menu_item_data );
                        wp_update_post( $next_item_data );
                    }

                    // The item is last but still has a parent, so bubble up.                 } elseif ( ! empty( $menu_item_data['menu_item_parent'] )
                    && in_array( (int) $menu_item_data['menu_item_parent']$orders_to_dbids, true )
                ) {
                    $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );

                    // Reset invalid `menu_item_parent`.                     $menu_item_data = _wp_reset_invalid_menu_item_parent( $menu_item_data );

                    update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
                }
            }
        }

        break;

    


            delete_meta( $key );
        }
    }

    // Attachment stuff.     if ( 'attachment' === $post_data['post_type'] ) {
        if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
            $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );

            if ( get_post_meta( $post_id, '_wp_attachment_image_alt', true ) !== $image_alt ) {
                $image_alt = wp_strip_all_tags( $image_alt, true );

                // update_post_meta() expects slashed.                 update_post_meta( $post_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
            }
        }

        $attachment_data = isset( $post_data['attachments'][ $post_id ] ) ? $post_data['attachments'][ $post_id ] : array();

        /** This filter is documented in wp-admin/includes/media.php */
        $translated = apply_filters( 'attachment_fields_to_save', $translated$attachment_data );
    }

            $post = apply_filters( 'attachment_fields_to_save', $post$attachment );

            if ( isset( $attachment['image_alt'] ) ) {
                $image_alt = wp_unslash( $attachment['image_alt'] );

                if ( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) !== $image_alt ) {
                    $image_alt = wp_strip_all_tags( $image_alt, true );

                    // update_post_meta() expects slashed.                     update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
                }
            }

            if ( isset( $post['errors'] ) ) {
                $errors[ $attachment_id ] = $post['errors'];
                unset( $post['errors'] );
            }

            

function get_page_template_slug( $post = null ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return false;
    }

    $template = get_post_meta( $post->ID, '_wp_page_template', true );

    if ( ! $template || 'default' === $template ) {
        return '';
    }

    return $template;
}

/** * Retrieves formatted date timestamp of a revision (linked to that revisions's page). * * @since 2.6.0 * * @param int|object $revision Revision ID or revision object. * @param bool $link Optional. Whether to link to revision's page. Default true. * @return string|false i18n formatted datetimestamp or localized 'Current Revision'. */
|| ( 'post_type' === $menu_item->type && $wp_query->is_singular )
                || ( 'taxonomy' === $menu_item->type
                    && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
                    && $queried_object->taxonomy == $menu_item->object )
            )
        ) {
            $classes[]                   = 'current-menu-item';
            $menu_items[ $key ]->current = true;
            $_anc_id                     = (int) $menu_item->db_id;

            while (
                ( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) )
                && ! in_array( $_anc_id$active_ancestor_item_ids, true )
            ) {
                $active_ancestor_item_ids[] = $_anc_id;
            }

            if ( 'post_type' === $menu_item->type && 'page' === $menu_item->object ) {
                // Back compat classes for pages to match wp_page_menu().                 $classes[] = 'page_item';
                $classes[] = 'page-item-' . $menu_item->object_id;
                $classes[] = 'current_page_item';
            }

            
'value' => get_bloginfo( 'url' ),
                ),
                array(
                    'name'  => _x( 'On', 'date/time' ),
                    'value' => current_time( 'mysql' ),
                ),
            ),
        ),
    );

    // And now, all the Groups.     $groups = get_post_meta( $request_id, '_export_data_grouped', true );
    if ( is_array( $groups ) ) {
        // Merge in the special "About" group.         $groups       = array_merge( array( 'about' => $about_group )$groups );
        $groups_count = count( $groups );
    } else {
        if ( false !== $groups ) {
            _doing_it_wrong(
                __FUNCTION__,
                /* translators: %s: Post meta key. */
                sprintf( __( 'The %s post meta must be an array.' ), '<code>_export_data_grouped</code>' ),
                '5.8.0'
            );
if ( ! $header->url ) {
        return '';
    }

    $width  = absint( $header->width );
    $height = absint( $header->height );
    $alt    = '';

    // Use alternative text assigned to the image, if available. Otherwise, leave it empty.     if ( ! empty( $header->attachment_id ) ) {
        $image_alt = get_post_meta( $header->attachment_id, '_wp_attachment_image_alt', true );

        if ( is_string( $image_alt ) ) {
            $alt = $image_alt;
        }
    }

    $attr = wp_parse_args(
        $attr,
        array(
            'src'      => $header->url,
            'width'    => $width,
            
return get_the_author();
}

/** * Retrieves the author who last edited the current post. * * @since 2.8.0 * * @return string|void The author's display name, empty string if unknown. */
function get_the_modified_author() {
    $last_id = get_post_meta( get_post()->ID, '_edit_last', true );

    if ( $last_id ) {
        $last_user = get_userdata( $last_id );

        /** * Filters the display name of the author who last edited the current post. * * @since 2.8.0 * * @param string $display_name The author's display name, empty string if unknown. */
        
if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) {
            /* * If on the home page, set the logo alt attribute to an empty string, * as the image is decorative and doesn't need its purpose to be described. */
            $custom_logo_attr['alt'] = '';
        } else {
            /* * If the logo alt attribute is empty, get the site title and explicitly pass it * to the attributes used by wp_get_attachment_image(). */
            $image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
            if ( empty( $image_alt ) ) {
                $custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
            }
        }

        /** * Filters the list of custom logo image attributes. * * @since 5.5.0 * * @param array $custom_logo_attr Custom logo image attributes. * @param int $custom_logo_id Custom logo attachment ID. * @param int $blog_id ID of the blog to get the custom logo for. */

function get_post_thumbnail_id( $post = null ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return false;
    }

    $thumbnail_id = (int) get_post_meta( $post->ID, '_thumbnail_id', true );

    /** * Filters the post thumbnail ID. * * @since 5.9.0 * * @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist. * @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. */
    return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id$post );
}

$attachment = get_post( $attachment_id );
        $hwstring   = image_hwstring( $width$height );
        $size_class = $size;

        if ( is_array( $size_class ) ) {
            $size_class = implode( 'x', $size_class );
        }

        $default_attr = array(
            'src'      => $src,
            'class'    => "attachment-$size_class size-$size_class",
            'alt'      => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
            'decoding' => 'async',
        );

        /** * Filters the context in which wp_get_attachment_image() is used. * * @since 6.3.0 * * @param string $context The context. Default 'wp_get_attachment_image'. */
        $context = apply_filters( 'wp_get_attachment_image_context', 'wp_get_attachment_image' );
        
if ( is_wp_error( $new_attachment_id ) ) {
            if ( 'db_update_error' === $new_attachment_id->get_error_code() ) {
                $new_attachment_id->add_data( array( 'status' => 500 ) );
            } else {
                $new_attachment_id->add_data( array( 'status' => 400 ) );
            }

            return $new_attachment_id;
        }

        // Copy the image alt text from the edited image.         $image_alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );

        if ( ! empty( $image_alt ) ) {
            // update_post_meta() expects slashed.             update_post_meta( $new_attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
        }

        if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
            /* * Set a custom header with the attachment_id. * Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. */
            
return $terms;
    }

    if ( ! $terms ) {
        return new WP_Error( 'template_missing_theme', __( 'No theme is defined for this template.' ) );
    }

    $theme          = $terms[0]->name;
    $template_file  = _get_block_template_file( $post->post_type, $post->post_name );
    $has_theme_file = get_stylesheet() === $theme && null !== $template_file;

    $origin           = get_post_meta( $post->ID, 'origin', true );
    $is_wp_suggestion = get_post_meta( $post->ID, 'is_wp_suggestion', true );

    $template                 = new WP_Block_Template();
    $template->wp_id          = $post->ID;
    $template->id             = $theme . '//' . $post->post_name;
    $template->theme          = $theme;
    $template->content        = $post->post_content;
    $template->slug           = $post->post_name;
    $template->source         = 'custom';
    $template->origin         = ! empty( $origin ) ? $origin : null;
    $template->type           = $post->post_type;
    

function render_block_core_footnotes( $attributes$content$block ) {
    // Bail out early if the post ID is not set for some reason.     if ( empty( $block->context['postId'] ) ) {
        return '';
    }

    if ( post_password_required( $block->context['postId'] ) ) {
        return;
    }

    $footnotes = get_post_meta( $block->context['postId'], 'footnotes', true );

    if ( ! $footnotes ) {
        return;
    }

    $footnotes = json_decode( $footnotes, true );

    if ( ! is_array( $footnotes ) || count( $footnotes ) === 0 ) {
        return '';
    }

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