get_post_field example

$args = wp_parse_args( $menu_item_data$defaults );

    if ( 0 == $menu_id ) {
        $args['menu-item-position'] = 1;
    } elseif ( 0 == (int) $args['menu-item-position'] ) {
        $menu_items                 = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
        $last_item                  = array_pop( $menu_items );
        $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items );
    }

    $original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;

    if ( 'custom' === $args['menu-item-type'] ) {
        // If custom menu item, trim the URL.         $args['menu-item-url'] = trim( $args['menu-item-url'] );
    } else {
        /* * If non-custom menu item, then: * - use the original object's URL. * - blank default title to sync with the original object's title. */

        

function render_block_core_post_author_biography( $attributes$content$block ) {
    if ( ! isset( $block->context['postId'] ) ) {
        return '';
    }

    $author_id = get_post_field( 'post_author', $block->context['postId'] );
    if ( empty( $author_id ) ) {
        return '';
    }

    $author_biography = get_the_author_meta( 'description', $author_id );
    if ( empty( $author_biography ) ) {
        return '';
    }

    $align_class_name   = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );

    
// Get the post ID and GUID.         $post_id     = $postarr['ID'];
        $post_before = get_post( $post_id );

        if ( is_null( $post_before ) ) {
            if ( $wp_error ) {
                return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
            }
            return 0;
        }

        $guid            = get_post_field( 'guid', $post_id );
        $previous_status = get_post_field( 'post_status', $post_id );
    } else {
        $previous_status = 'new';
        $post_before     = null;
    }

    $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type'];

    $post_title   = $postarr['post_title'];
    $post_content = $postarr['post_content'];
    $post_excerpt = $postarr['post_excerpt'];

    

function render_block_core_post_author( $attributes$content$block ) {
    if ( ! isset( $block->context['postId'] ) ) {
        $author_id = get_query_var( 'author' );
    } else {
        $author_id = get_post_field( 'post_author', $block->context['postId'] );
    }

    if ( empty( $author_id ) ) {
        return '';
    }

    $avatar = ! empty( $attributes['avatarSize'] ) ? get_avatar(
        $author_id,
        $attributes['avatarSize']
    ) : null;

    

function render_block_core_post_author_name( $attributes$content$block ) {
    if ( ! isset( $block->context['postId'] ) ) {
        return '';
    }

    $author_id = get_post_field( 'post_author', $block->context['postId'] );
    if ( empty( $author_id ) ) {
        return '';
    }

    $author_name = get_the_author_meta( 'display_name', $author_id );
    if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
        $author_name = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', get_author_posts_url( $author_id )esc_attr( $attributes['linkTarget'] )$author_name );
    }

    $classes = array();
    if ( isset( $attributes['textAlign'] ) ) {
        
$post_data['post_status'] = 'draft';
    }
    if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
        $post_data['post_status'] = 'pending';
    }

    if ( isset( $post_data['ID'] ) ) {
        $post_id = $post_data['ID'];
    } else {
        $post_id = false;
    }
    $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;

    if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
        $post_data['post_status'] = $previous_status ? $previous_status : 'pending';
    }

    $published_statuses = array( 'publish', 'future' );

    /* * Posts 'submitted for approval' are submitted to $_POST the same as if they were being published. * Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. */
    
 "wp-block-avatar__image {$border_attributes['class']}"
        : 'wp-block-avatar__image';

    // Unlike class, `get_avatar` doesn't filter the styles via `esc_attr`.     // The style engine does pass the border styles through     // `safecss_filter_attr` however.     $image_styles = ! empty( $border_attributes['style'] )
        ? sprintf( ' style="%s"', esc_attr( $border_attributes['style'] ) )
        : '';

    if ( ! isset( $block->context['commentId'] ) ) {
        $author_id   = isset( $attributes['userId'] ) ? $attributes['userId'] : get_post_field( 'post_author', $block->context['postId'] );
        $author_name = get_the_author_meta( 'display_name', $author_id );
        // translators: %s is the Author name.         $alt          = sprintf( __( '%s Avatar' )$author_name );
        $avatar_block = get_avatar(
            $author_id,
            $size,
            '',
            $alt,
            array(
                'extra_attr' => $image_styles,
                'class'      => $image_classes,
            )
Home | Imprint | This part of the site doesn't use cookies.