[wp-trac] [WordPress Trac] #9868: the_title(), the_content(), the_permalink(), etc inconsistencies

WordPress Trac wp-trac at lists.automattic.com
Tue Jan 19 00:57:15 UTC 2010


#9868: the_title(), the_content(), the_permalink(), etc inconsistencies
-------------------------+--------------------------------------------------
  Reporter:  archon810   |        Type:  enhancement
    Status:  closed      |    Priority:  normal     
 Milestone:              |   Component:  Template   
   Version:  2.7.1       |    Severity:  normal     
Resolution:  worksforme  |    Keywords:             
-------------------------+--------------------------------------------------
Changes (by scribu):

  * status:  new => closed
  * resolution:  => worksforme
  * milestone:  Future Release =>


Comment:

 Replying to [comment:5 archon810]:
 > OK, I got it all sorted now. Here is the final outcome, for whoever is
 interested:
 >
 >     * Each post's data can be accessed via iterating through the array
 returned by get_posts(), but this data will just be whatever is in the
 database, without passing through any intermediate filters
 >     * The preferred way is to access data using get_the_ functions and
 them wrapping them in an call to apply_filters() with the appropriate
 filter. This way, all intermediate filters will be applied.
 >
 >
 > {{{
 > apply_filters('the_permalink', get_permalink())
 > }}}
 >
 >
 >     * the reason why get_the_content() was returning an empty string is
 that apparently a special call to setup_postdata($post); needs to be done
 first. Then get_the_content() returns data properly.
 >
 > Am I on the right track here?

 Yes, you need to call {{{setup_postdata($post);}}}

 But a better solution would be to use a custom loop:

 {{{
 $query = new WP_Query( ...query vars... );

 while ( $query->has_posts() ) : $query->the_post();
   $content = apply_filters('the_content', get_the_content());
 endwhile;
 }}}

 I think that's an acceptable workaround.

 Closing for lack of traction.

 Feel free to reopen if you have a patch.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9868#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list