get_post example



    remove_filter( 'pre_get_posts', '_resolve_template_for_new_post' );

    // Pages.     $page_id = isset( $wp_query->query['page_id'] ) ? $wp_query->query['page_id'] : null;

    // Posts, including custom post types.     $p = isset( $wp_query->query['p'] ) ? $wp_query->query['p'] : null;

    $post_id = $page_id ? $page_id : $p;
    $post    = get_post( $post_id );

    if (
        $post &&
        'auto-draft' === $post->post_status &&
        current_user_can( 'edit_post', $post->ID )
    ) {
        $wp_query->set( 'post_status', 'auto-draft' );
    }
}

function has_blocks( $post = null ) {
    if ( ! is_string( $post ) ) {
        $wp_post = get_post( $post );

        if ( ! $wp_post instanceof WP_Post ) {
            return false;
        }

        $post = $wp_post->post_content;
    }

    return str_contains( (string) $post, '<!-- wp:' );
}

'no_found_rows'          => true,
        'cache_results'          => true,
        'update_post_meta_cache' => false,
        'update_post_term_cache' => false,
        'lazy_load_term_meta'    => false,
    );

    $post = null;
    if ( get_stylesheet() === $stylesheet ) {
        $post_id = get_theme_mod( 'custom_css_post_id' );

        if ( $post_id > 0 && get_post( $post_id ) ) {
            $post = get_post( $post_id );
        }

        // `-1` indicates no post exists; no query necessary.         if ( ! $post && -1 !== $post_id ) {
            $query = new WP_Query( $custom_css_query_vars );
            $post  = $query->post;
            /* * Cache the lookup. See wp_update_custom_css_post(). * @todo This should get cleared if a custom_css post is added/removed. */
            
// Put the original shortcodes back.         $shortcode_tags = $orig_shortcode_tags;

        return $content;
    }

    /** * If a post/page was saved, then output JavaScript to make * an Ajax request that will call WP_Embed::cache_oembed(). */
    public function maybe_run_ajax_cache() {
        $post = get_post();

        if ( ! $post || empty( $_GET['message'] ) ) {
            return;
        }
        ?> <script type="text/javascript"> jQuery( function($) { $.get("<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ) . '?action=oembed-cache&post=' . $post->ID; ?>"); } ); </script> <?php
class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {

    /** * Gets the nav menu item, if the ID is valid. * * @since 5.9.0 * * @param int $id Supplied ID. * @return object|WP_Error Post object if ID is valid, WP_Error otherwise. */
    protected function get_nav_menu_item( $id ) {
        $post = $this->get_post( $id );
        if ( is_wp_error( $post ) ) {
            return $post;
        }

        return wp_setup_nav_menu_item( $post );
    }

    /** * Checks if a given request has access to read menu items. * * @since 5.9.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access, WP_Error object otherwise. */
wp_ajax_upload_attachment();
    die( '0' );
}

if ( ! current_user_can( 'upload_files' ) ) {
    wp_die( __( 'Sorry, you are not allowed to upload files.' ) );
}

// Just fetch the detail form for that attachment. if ( isset( $_REQUEST['attachment_id'] ) && (int) $_REQUEST['attachment_id'] && $_REQUEST['fetch'] ) {
    $id   = (int) $_REQUEST['attachment_id'];
    $post = get_post( $id );
    if ( 'attachment' !== $post->post_type ) {
        wp_die( __( 'Invalid post type.' ) );
    }

    switch ( $_REQUEST['fetch'] ) {
        case 3:
            ?> <div class="media-item-wrapper"> <div class="attachment-details"> <?php                     $thumb_url = wp_get_attachment_image_src( $id, 'thumbnail', true );
                    
/** * Gets the REST API route for a post. * * @since 5.5.0 * * @param int|WP_Post $post Post ID or post object. * @return string The route path with a leading slash for the given post, * or an empty string if there is not a route. */
function rest_get_route_for_post( $post ) {
    $post = get_post( $post );

    if ( ! $post instanceof WP_Post ) {
        return '';
    }

    $post_type_route = rest_get_route_for_post_type_items( $post->post_type );
    if ( ! $post_type_route ) {
        return '';
    }

    $route = sprintf( '%s/%d', $post_type_route$post->ID );

    
                $dropdown = str_replace( '<select', '<select ' . $this->get_link() . ' id="' . esc_attr( $input_id ) . '" ' . $describedby_attr$dropdown );

                /* * Even more hacikly add auto-draft page stubs. * @todo Eventually this should be removed in favor of the pages being injected into the underlying get_pages() call. * See <https://github.com/xwp/wp-customize-posts/pull/250>. */
                $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
                if ( $nav_menus_created_posts_setting && current_user_can( 'publish_pages' ) ) {
                    $auto_draft_page_options = '';
                    foreach ( $nav_menus_created_posts_setting->value() as $auto_draft_page_id ) {
                        $post = get_post( $auto_draft_page_id );
                        if ( $post && 'page' === $post->post_type ) {
                            $auto_draft_page_options .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $post->ID )esc_html( $post->post_title ) );
                        }
                    }
                    if ( $auto_draft_page_options ) {
                        $dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown );
                    }
                }

                echo $dropdown;
                ?>

            if ( ! empty( $value ) && empty( $value['original_title'] ) ) {
                $value['original_title'] = $this->get_original_title( (object) $value );
            }
        } elseif ( isset( $this->value ) ) {
            $value = $this->value;
        } else {
            $value = false;

            // Note that an ID of less than one indicates a nav_menu not yet inserted.             if ( $this->post_id > 0 ) {
                $post = get_post( $this->post_id );
                if ( $post && self::POST_TYPE === $post->post_type ) {
                    $is_title_empty = empty( $post->post_title );
                    $value          = (array) wp_setup_nav_menu_item( $post );
                    if ( $is_title_empty ) {
                        $value['title'] = '';
                    }
                }
            }

            if ( ! is_array( $value ) ) {
                $value = $this->default;
            }
/** * Retrieves the terms of the taxonomy that are attached to the post. * * @since 2.5.0 * * @param int|WP_Post $post Post ID or object. * @param string $taxonomy Taxonomy name. * @return WP_Term[]|false|WP_Error Array of WP_Term objects on success, false if there are no terms * or the post does not exist, WP_Error on failure. */
function get_the_terms( $post$taxonomy ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return false;
    }

    $terms = get_object_term_cache( $post->ID, $taxonomy );

    if ( false === $terms ) {
        $terms = wp_get_object_terms( $post->ID, $taxonomy );
        if ( ! is_wp_error( $terms ) ) {
            $term_ids = wp_list_pluck( $terms, 'term_id' );
            

    function wp_notify_postauthor( $comment_id$deprecated = null ) {
        if ( null !== $deprecated ) {
            _deprecated_argument( __FUNCTION__, '3.8.0' );
        }

        $comment = get_comment( $comment_id );
        if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) {
            return false;
        }

        $post   = get_post( $comment->comment_post_ID );
        $author = get_userdata( $post->post_author );

        // Who to notify? By default, just the post author, but others can be added.         $emails = array();
        if ( $author ) {
            $emails[] = $author->user_email;
        }

        /** * Filters the list of email addresses to receive a comment notification. * * By default, only post authors are notified of comments. This filter allows * others to be added. * * @since 3.7.0 * * @param string[] $emails An array of email addresses to receive a comment notification. * @param string $comment_id The comment ID as a numeric string. */

function get_postdata($postid) {
    _deprecated_function( __FUNCTION__, '1.5.1', 'get_post()' );

    $post = get_post($postid);

    $postdata = array (
        'ID' => $post->ID,
        'Author_ID' => $post->post_author,
        'Date' => $post->post_date,
        'Content' => $post->post_content,
        'Excerpt' => $post->post_excerpt,
        'Title' => $post->post_title,
        'Category' => $post->post_category,
        'post_status' => $post->post_status,
        'comment_status' => $post->comment_status,
        

$post_ID = $post_id;

/** * @global string $post_type * @global object $post_type_object * @global WP_Post $post Global post object. */
global $post_type$post_type_object$post;

if ( $post_id ) {
    $post = get_post( $post_id );
}

if ( $post ) {
    $post_type        = $post->post_type;
    $post_type_object = get_post_type_object( $post_type );
}

if ( isset( $_POST['post_type'] ) && $post && $post_type !== $_POST['post_type'] ) {
    wp_die( __( 'A post type mismatch has been detected.' )__( 'Sorry, you are not allowed to edit this item.' ), 400 );
}

'_wpnonce',
        );

        $original_title = false;

        if ( 'taxonomy' === $menu_item->type ) {
            $original_object = get_term( (int) $menu_item->object_id, $menu_item->object );
            if ( $original_object && ! is_wp_error( $original_object ) ) {
                $original_title = $original_object->name;
            }
        } elseif ( 'post_type' === $menu_item->type ) {
            $original_object = get_post( $menu_item->object_id );
            if ( $original_object ) {
                $original_title = get_the_title( $original_object->ID );
            }
        } elseif ( 'post_type_archive' === $menu_item->type ) {
            $original_object = get_post_type_object( $menu_item->object );
            if ( $original_object ) {
                $original_title = $original_object->labels->archives;
            }
        }

        $classes = array(
            

    public function __isset( $name ) {
        if ( in_array( $name$this->post_fields, true ) && 0 !== (int) $this->comment_post_ID ) {
            $post = get_post( $this->comment_post_ID );
            return property_exists( $post$name );
        }
    }

    /** * Magic getter. * * If `$name` matches a post field, the comment post will be loaded and the post's value returned. * * @since 4.4.0 * * @param string $name * @return mixed */
Home | Imprint | This part of the site doesn't use cookies.