[wp-hackers] Idea to enhance the WP_Post class

Funkatron funkatronic at gmail.com
Fri Apr 5 05:43:31 UTC 2013


This idea is a simple one: encapsulating the post-based template tags
(the_ID, the_title, the_content, etc) and make them methods of the WP_Post
object.

Basically what this does is allow developers and theme makers to take
advantage of the template tags in custom loops without actually messing
around with the main loop or the global $post and removing the need to
reset post data. Since the template tags use post data to begin, it makes
sense for the core logic to be in the WP_Post class. The global template
tags can just call the methods of the global $post object in a main loop.

For example if you have a custom query:

$query = new WP_Query();

Instead of calling the_post to load the global variables, you could do:

while( $query->have_posts ) : $query->next_post();
    $query->post->the_title();
    $query->post->the_content();
endwhile;

Basically, you call the template tags directly from the post instead of
messing with the main loop variables.


More information about the wp-hackers mailing list