[wp-hackers] Access $post near template_include

Mario Peshev mario at peshev.net
Sun Jul 22 21:19:20 UTC 2012


Some very idiotic question here, got the add_filter line commented and the
same function used as another hook on the line above it.

Thanks Mike, pretty much better now.

Mario Peshev
Training and Consulting Services @ DevriX
http://www.linkedin.com/in/mpeshev
http://devrix.com
http://peshev.net/blog



On Sun, Jul 22, 2012 at 10:22 PM, Mike Schinkel <mike at newclarity.net> wrote:

> On Jul 22, 2012, at 8:21 AM, Mario Peshev wrote:
> > I'm trying to do some on-the-fly manipulations on the page template that
> > take place in template-loader.php, by filtering the template_include part
> > at the end. However I am not sure how to get the post ID there as I still
> > don't have an access to the global variables for post and the loop and I
> > also can't get it from the server variable due to permalink specifics.
> >
> > Is there a workaround to get the post ID at that point of loading?
>
> The global variable $post is available by the time the 'template_include'
> hook fires.  Add this to your theme's functions.php file to see it in
> action:
>
> add_filter( 'template_include', 'marios_template_include' );
> function marios_template_include( $template_file ) {
>   global $post;
>   echo "Post ID: " . $post->ID . "</br>";
>   return $template_file;
> }
>
> Hope this helps.
>
> -Mike
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list