generate_postdata example

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

    /* * Use the globals if the $post parameter was not specified, * but only after they have been set up in setup_postdata(). */
    if ( null === $post && did_action( 'the_post' ) ) {
        $elements = compact( 'page', 'more', 'preview', 'pages', 'multipage' );
    } else {
        $elements = generate_postdata( $_post );
    }

    if ( null === $more_link_text ) {
        $more_link_text = sprintf(
            '<span aria-label="%1$s">%2$s</span>',
            sprintf(
                /* translators: %s: Post title. */
                __( 'Continue reading %s' ),
                the_title_attribute(
                    array(
                        'echo' => false,
                        

function generate_postdata( $post ) {
    global $wp_query;

    if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
        return $wp_query->generate_postdata( $post );
    }

    return false;
}
public function setup_postdata( $post ) {
        global $id$authordata$currentday$currentmonth$page$pages$multipage$more$numpages;

        if ( ! ( $post instanceof WP_Post ) ) {
            $post = get_post( $post );
        }

        if ( ! $post ) {
            return;
        }

        $elements = $this->generate_postdata( $post );
        if ( false === $elements ) {
            return;
        }

        $id           = $elements['id'];
        $authordata   = $elements['authordata'];
        $currentday   = $elements['currentday'];
        $currentmonth = $elements['currentmonth'];
        $page         = $elements['page'];
        $pages        = $elements['pages'];
        $multipage    = $elements['multipage'];
        
Home | Imprint | This part of the site doesn't use cookies.