Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need a hook such that when visitor lands on any of the post (not page), I need to record a hit.

How can I find whether the request is for post, and is there any hook to find if the loaded content is post, and if yes, what is post id

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

something like this will work:

function record_hit_if_post(){
    global $wp_query;
    if($wp_query->is_single==1)
        // single post's ID:
        // $wp_query->post->ID;
}
add_filter('template_redirect', 'record_hit_if_post');
share|improve this answer
    
is_single might come up with page too, don't you think so? –  I-M-JM May 3 '11 at 2:22
1  
no, just single post. is_page == 1 on a page –  Milo May 3 '11 at 3:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.