[wp-hackers] get post Id from url (when mod_Rewrite enabled)

Vladimir Ghetau vladimir at pixeltomorrow.com
Thu Dec 27 12:32:57 GMT 2007


Hi guys and Merry Christmas,

I'm using an action hook 'init', that will try to get the post ID 
based on the specific URL that's being visited by the user.

When no url rewriting is used, I can grab the post id using 
$_GET['p'].

However, when URL , rewriting is in use, and I use the post_name 
slug line inside the link, I can't grab the post id at all. I 
tried to play with the WP_rewrite class, and nothing. I also did 
a print_r($_GET) and no slug shows up (thinking I'll do a MySQL 
select to extract my id).

I can't figure out a solution right now, and I'm looking forward
to some opinions.

The reason I'm not using the_ID() method or the global loopable 
$id variable, it's because I'm using the 'init' action hook, 
which doesn't work when no output or wp processing script has 
been called yet, so the only way to extract a single post/page 
id, is to grab the query.

I'm loooking forward to any small/big tip :)

Thanks,

Vladimir Ghetau
http://www.Vladimirated.com/


More information about the wp-hackers mailing list