Make WordPress Core

Changeset 12877


Ignore:
Timestamp:
01/27/2010 05:45:49 PM (14 years ago)
Author:
ryan
Message:

Avoid call to setup_postdata(). Use get_queried_object_id(). Props filosofo. fixes #11439

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r12751 r12877  
    393393
    394394    if ( is_single() ) {
    395         $wp_query->post = $wp_query->posts[0];
    396         setup_postdata($wp_query->post);
    397 
    398         $postID = $wp_query->post->ID;
     395        $postID = $wp_query->get_queried_object_id();
     396       
    399397        $classes[] = 'single postid-' . $postID;
    400398
    401399        if ( is_attachment() ) {
    402             $mime_type = get_post_mime_type();
     400            $mime_type = get_post_mime_type($postID);
    403401            $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
    404402            $classes[] = 'attachmentid-' . $postID;
     
    422420        $classes[] = 'page';
    423421
    424         $wp_query->post = $wp_query->posts[0];
    425         setup_postdata($wp_query->post);
    426 
    427         $pageID = $wp_query->post->ID;
     422        $pageID = $wp_query->get_queried_object_id();
     423
     424        $post = get_page($pageID);
    428425
    429426        $classes[] = 'page-id-' . $pageID;
    430427
    431         if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' LIMIT 1", $pageID) ) )
     428        if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $pageID) ) )
    432429            $classes[] = 'page-parent';
    433430
    434         if ( $wp_query->post->post_parent ) {
     431        if ( $post->post_parent ) {
    435432            $classes[] = 'page-child';
    436             $classes[] = 'parent-pageid-' . $wp_query->post->post_parent;
     433            $classes[] = 'parent-pageid-' . $post->post_parent;
    437434        }
    438435        if ( is_page_template() ) {
Note: See TracChangeset for help on using the changeset viewer.