get_post_type example



/** * Determines whether the given ID is a nav menu item. * * @since 3.0.0 * * @param int $menu_item_id The ID of the potential nav menu item. * @return bool Whether the given ID is that of a nav menu item. */
function is_nav_menu_item( $menu_item_id = 0 ) {
    return ( ! is_wp_error( $menu_item_id ) && ( 'nav_menu_item' === get_post_type( $menu_item_id ) ) );
}

/** * Creates a navigation menu. * * Note that `$menu_name` is expected to be pre-slashed. * * @since 3.0.0 * * @param string $menu_name Menu name. * @return int|WP_Error Menu ID on success, WP_Error object on failure. */
 elseif ( isset( $request['excerpt']['raw'] ) ) {
                $prepared_post->post_excerpt = $request['excerpt']['raw'];
            }
        }

        // Post type.         if ( empty( $request['id'] ) ) {
            // Creating new post, use default type for the controller.             $prepared_post->post_type = $this->post_type;
        } else {
            // Updating a post, use previous type.             $prepared_post->post_type = get_post_type( $request['id'] );
        }

        $post_type = get_post_type_object( $prepared_post->post_type );

        // Post status.         if (
            ! empty( $schema['properties']['status'] ) &&
            isset( $request['status'] ) &&
            ( ! $current_status || $current_status !== $request['status'] )
        ) {
            $status = $this->handle_status_param( $request['status']$post_type );

            

    function block_core_calendar_update_has_published_post_on_transition_post_status( $new_status$old_status$post ) {
        if ( $new_status === $old_status ) {
            return;
        }

        if ( 'post' !== get_post_type( $post ) ) {
            return;
        }

        if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
            return;
        }

        block_core_calendar_update_has_published_posts();
    }

    add_action( 'delete_post', 'block_core_calendar_update_has_published_post_on_delete' );
    
__( 'Undo' )
        );
    }

    if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
        $ids = explode( ',', $_REQUEST['ids'] );

        if ( 1 === count( $ids ) && current_user_can( 'edit_post', $ids[0] ) ) {
            $messages[] = sprintf(
                '<a href="%1$s">%2$s</a>',
                esc_url( get_edit_post_link( $ids[0] ) ),
                esc_html( get_post_type_object( get_post_type( $ids[0] ) )->labels->edit_item )
            );
        }
    }
}

if ( $messages ) {
    printf(
        '<div id="message" class="updated notice is-dismissible"><p>%s</p></div>',
        implode( ' ', $messages )
    );
}
$template_types = get_block_templates();

        foreach ( $template_types as $template_type ) {
            if ( 'page' === $template_type->slug ) {
                $page_slug = 'page';
            }
            if ( 'single' === $template_type->slug ) {
                $post_slug = 'single';
            }
        }

        $what_post_type = get_post_type( $post_ID );
        switch ( $what_post_type ) {
            case 'page':
                $template_slug = $page_slug;
                break;
            default:
                $template_slug = $post_slug;
                break;
        }
    }

    $current_template = get_block_templates( array( 'slug__in' => array( $template_slug ) ) );

    

?> <div <?php post_class( 'wp-embed' ); ?>> <?php         $thumbnail_id = 0;

        if ( has_post_thumbnail() ) {
            $thumbnail_id = get_post_thumbnail_id();
        }

        if ( 'attachment' === get_post_type() && wp_attachment_is_image() ) {
            $thumbnail_id = get_the_ID();
        }

        /** * Filters the thumbnail image ID for use in the embed template. * * @since 4.9.0 * * @param int|false $thumbnail_id Attachment ID, or false if there is none. */
        $thumbnail_id = apply_filters( 'embed_thumbnail_id', $thumbnail_id );

        
$sample = true;
    } else {
        $post   = get_post( $post );
        $sample = null !== $sample ? $sample : false;
    }

    if ( ! $post ) {
        return true;
    }

    $post_status_obj = get_post_status_object( get_post_status( $post ) );
    $post_type_obj   = get_post_type_object( get_post_type( $post ) );

    if ( ! $post_status_obj || ! $post_type_obj ) {
        return true;
    }

    if (
        // Publicly viewable links never have plain permalinks.         is_post_status_viewable( $post_status_obj ) ||
        (
            // Private posts don't have plain permalinks if the user can read them.             $post_status_obj->private &&
            

    protected function has_content( $instance ) {
        if ( ! empty( $instance['ids'] ) ) {
            $attachments = wp_parse_id_list( $instance['ids'] );
            foreach ( $attachments as $attachment ) {
                if ( 'attachment' !== get_post_type( $attachment ) ) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }
}

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

    if ( ! $post ) {
        return false;
    }

    $post_type   = get_post_type( $post );
    $post_status = get_post_status( $post );

    return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
}

/** * Retrieves an array of the latest posts, or posts matching the given criteria. * * For more information on the accepted arguments, see the * {@link https://developer.wordpress.org/reference/classes/wp_query/ * WP_Query} documentation in the Developer Handbook. * * The `$ignore_sticky_posts` and `$no_found_rows` arguments are ignored by * this function and both are set to `true`. * * The defaults are as follows: * * @since 1.2.0 * * @see WP_Query * @see WP_Query::parse_query() * * @param array $args { * Optional. Arguments to retrieve posts. See WP_Query::parse_query() for all available arguments. * * @type int $numberposts Total number of posts to retrieve. Is an alias of `$posts_per_page` * in WP_Query. Accepts -1 for all. Default 5. * @type int|string $category Category ID or comma-separated list of IDs (this or any children). * Is an alias of `$cat` in WP_Query. Default 0. * @type int[] $include An array of post IDs to retrieve, sticky posts will be included. * Is an alias of `$post__in` in WP_Query. Default empty array. * @type int[] $exclude An array of post IDs not to retrieve. Default empty array. * @type bool $suppress_filters Whether to suppress filters. Default true. * } * @return WP_Post[]|int[] Array of post objects or post IDs. */


    /** * Whether the widget has content to show. * * @since 4.8.0 * * @param array $instance Widget instance props. * @return bool Whether widget has content. */
    protected function has_content( $instance ) {
        return ( $instance['attachment_id'] && 'attachment' === get_post_type( $instance['attachment_id'] ) ) || $instance['url'];
    }

    /** * Returns the default description of the widget. * * @since 6.0.0 * * @return string */
    protected static function get_default_description() {
        if ( self::$default_description ) {
            

    public function find_oembed_post_id( $cache_key ) {
        $cache_group    = 'oembed_cache_post';
        $oembed_post_id = wp_cache_get( $cache_key$cache_group );

        if ( $oembed_post_id && 'oembed_cache' === get_post_type( $oembed_post_id ) ) {
            return $oembed_post_id;
        }

        $oembed_post_query = new WP_Query(
            array(
                'post_type'              => 'oembed_cache',
                'post_status'            => 'publish',
                'name'                   => $cache_key,
                'posts_per_page'         => 1,
                'no_found_rows'          => true,
                'cache_results'          => true,
                
$data['height'] = absint( $height );
    $data['type']   = 'rich';
    $data['html']   = get_post_embed_html( $width$height$post );

    // Add post thumbnail to response if available.     $thumbnail_id = false;

    if ( has_post_thumbnail( $post->ID ) ) {
        $thumbnail_id = get_post_thumbnail_id( $post->ID );
    }

    if ( 'attachment' === get_post_type( $post ) ) {
        if ( wp_attachment_is_image( $post ) ) {
            $thumbnail_id = $post->ID;
        } elseif ( wp_attachment_is( 'video', $post ) ) {
            $thumbnail_id = get_post_thumbnail_id( $post );
            $data['type'] = 'video';
        }
    }

    if ( $thumbnail_id ) {
        list( $thumbnail_url$thumbnail_width$thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) );
        $data['thumbnail_url']                                      = $thumbnail_url;
        


if ( ! function_exists( 'twenty_twenty_one_posted_by' ) ) {
    /** * Prints HTML with meta information about theme author. * * @since Twenty Twenty-One 1.0 * * @return void */
    function twenty_twenty_one_posted_by() {
        if ( ! get_the_author_meta( 'description' ) && post_type_supports( get_post_type(), 'author' ) ) {
            echo '<span class="byline">';
            printf(
                /* translators: %s: Author name. */
                esc_html__( 'By %s', 'twentytwentyone' ),
                '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '" rel="author">' . esc_html( get_the_author() ) . '</a>'
            );
            echo '</span>';
        }
    }
}

while ( $query->have_posts() ) {
        $query->the_post();

        // Get an instance of the current Post Template block.         $block_instance = $block->parsed_block;

        // Set the block name to one that does not correspond to an existing registered block.         // This ensures that for the inner instances of the Post Template block, we do not render any block supports.         $block_instance['blockName'] = 'core/null';

        $post_id              = get_the_ID();
        $post_type            = get_post_type();
        $filter_block_context = static function( $context ) use ( $post_id$post_type ) {
            $context['postType'] = $post_type;
            $context['postId']   = $post_id;
            return $context;
        };

        // Use an early priority to so that other 'render_block_context' filters have access to the values.         add_filter( 'render_block_context', $filter_block_context, 1 );
        // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling         // `render_callback` and ensure that no wrapper markup is included.         $block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );
        


    /** * Creates a single attachment. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, WP_Error object on failure. */
    public function create_item( $request ) {
        if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) {
            return new WP_Error(
                'rest_invalid_param',
                __( 'Invalid parent type.' ),
                array( 'status' => 400 )
            );
        }

        $insert = $this->insert_attachment( $request );

        if ( is_wp_error( $insert ) ) {
            return $insert;
        }
Home | Imprint | This part of the site doesn't use cookies.