WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The code below is from this link. It basically creates a hit counter, but I'm probably gonna have to do this by IP.

How do I make a WP_Query, where only posts up to 1000 views can be seen on the trending list? Of course. I would want to do it by date as well, but it won't appear at the top one after another, it will only be in the list where it was originally posted. So, that's another solution I'm gonna need to figure out.

This is similar to 9GAG.

//Add to functions.php
    function get_hits(){
    global $post;
    $hits = get_post_meta($post->ID, '_hit-counter', true);
    return $hits;

function update_hits($count){
    global $post;
    $count = $count ? $count : 0;
    $hits = update_post_meta($post->ID, '_hit-counter', $count++);
    return $hits;

//Usage within the loop
share|improve this question

This should work, but I didn't have the time to test it.

$query = new WP_Query( array( 'meta_key' => '_hit-counter', 'meta_value' => '1000', 'meta_compare' => '>=', 'orderby' => 'date' ) );
share|improve this answer

Your Answer


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.