Check my latest reply to your other forum thread:
http://wordpress.org/support/topic/51561#post-284675
I think get_postdata() is a good way around your problems. Here’s the post data you can collect (RE: example of $post['SOMETHING']
provided):
'Title'
'Content'
'Date'
'Excerpt'
To return the permalink for a post, just use:
get_permalink($post_ID)
Thanks Kafkaesqui. I’ve actually been playing around with that method (got the idea from another plugin). I haven’t been able to find much about get_postdata(). Is it a new function? Or a very old one?
It would be nice to use get_excerpt() because, at least what I undestand, the auto-creation of an excerpt if it doesn’t already exist.
Is there a reason why the normal template tags don’t work outside the Loop?
No, get_postdata() is not new. In fact, if one looks at the source for the function they’d find it still uses $tableposts in its SQL query instead of the more proper (since 1.5) $wpdb->posts. Speaking of which (if you want to avoid deprecated functions), you could also try using get_post() — which is new:
$post = get_post($post_ID);
and then assign your variables through the post object’s class attributes or variables:
$post_title = $post->post_title;
$post_content = $post->post_content;
and so on.
The issue with “The Loop”-specific functions is, they need the post object to be cached and available. Run out of the Loop there’s no guarantee it will be. Fortunately there are ways to force it.
EDIT: Thought I’d note that functions like get_postdata() and get_post() are considered internal functions (i.e. not “template tags”), so documentation you might find on them is going to be slight, if at all. Hard enough documenting all the functions users are supposed to know about…
Thanks again. I got your previous method to work but I think I’ll update it to use get_post().
Just for learning sake, what ways are there for forcing the post object to be cached?
Two I mention above.
In many cases one can scope $wp_query to global, then call the post object through $wp_query->post. This is typically used in a function/plugin run off single post queries and the like. Hence my original suggestion in the other thread.
Hmmm…I wonder why it didn’t work. I’ll keep playing around with it and post if I find anything. Regardless, the get_post() method will work. Thanks a bunch.