[wp-trac] [WordPress Trac] #42958: create callers for loop functions to accept post id

WordPress Trac noreply at wordpress.org
Thu Dec 21 17:23:37 UTC 2017


#42958: create callers for loop functions to accept post id
--------------------------+-----------------------------
 Reporter:  tazotodua     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I've always been surprised, why the loop functions (like `the_title`,
 `the_content`, `the_post_thumbnail` and etc) doesnt have ability to accept
 post-id as argument.
 I think that the `get_.....` functions is not replacement in MANY MANY
 cases, whereas `the_...` functions automatically generate all the needed
 attributes and tags. using the `get_` function, it is hard to hardcode all
 those things manually.
 I suggest to revise once again and why wont WP create callers, like i.e.

 `_the_content($post_id, [other parameters as of now...])`
 `_the_title($post_id, [other parameters as of now...])`
 etc...

 this will make the things much easier for developers. If you dont believe,
 see how hard it is to get the same result as `the_content` for specific
 post id (while outside of loop):



 {{{
 //save global variable
 $target_post_id = 14;
 $p=$GLOBALS['post'];

 //change global variable temporarily, to deceive WP
 $GLOBALS['post']=get_post($target_post_id);
 //ONLY NOW call get_the_content
 $content = get_the_content( $more_link_text='Read more',
 $strip_teaser=false );
 $content = apply_filters( 'the_content', $content );
 $content = str_replace( ']]>', ']]>', $content );

 //restore the global variable
 $GLOBALS['post']=$p;

 echo $content;
 }}}

 this is real equivalent of `the_content` when you need to call outside of
 loop.  Is it still arguable??

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42958>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list