WordPress.org

Make WordPress Core

Opened 22 months ago

#42958 new defect (bug)

create callers for loop functions to accept post id

Reported by: tazotodua Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:
PR Number:

Description

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??

Change History (0)

Note: See TracTickets for help on using tickets.