WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Grabbing WordPress Statistics Data in the Loop

[Resolved] Grabbing WordPress Statistics Data in the Loop

  • I want to grab WordPress Statistics data for each post while in the loop. Is there any way to do it?

    E.G.

    <?php
    $recentPosts = new WP_Query();
    $recentPosts->query(‘cat=-8&showposts=3’);
    ?>
    <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    <?php
    $hits = POST HITS
    $todayshits = HOW MANY POST HITS TODAY

    Is anything like this even remotely possible?

    Thanks,

    Jordan

Viewing 10 replies - 1 through 10 (of 10 total)
  • Might have to write your own, but here’s the structure of the data
    http://stats.wordpress.com/csv.php

    MichaelH, thanks for posting the API URL. That is exactly right.
    JordashTalon, please make sure you don’t try to make ten API requests for every request you get. I would advise you to cache the results of any stats API queries and tally them yourself for a while. Your page load times will thank you.

    Michael, I’m not completely sure how to use that URL you pointed me too? I’d be fine righting my own, but is there a tutorial anywhere to show what to do with that URL? I don’t know what to make of it.

    Best I can do is point you to that link above where there’s an example url to get your data.

    If you want a simple template tag to display info to visitors then you might consider another popular posts type plugin.

    http://wordpress.org/extend/plugins/tags/popular

    The thing I don’t get is the link you sent me when I go to it it says

    Error: api_key is a required parameter.

    When I put in my personal API key it says that the API Key does not belong to the blog owner.

    Does wordpress have a csv.php file in my own wordpress installation that I can use to pull the data from?

    Not much I can add except to make sure you are using the correct blog id.

    But Where do I get the Blog ID? I just need a basic introduction to using that page?

    Not sure since I don’t use that plugin but it says:

    Find it in other stats URLs. So look at some of the other stats from that plugin and maybe need to login at wordpress.com to see that. Good Luck.

    It’s stashed away to make a treasure hunt. It’s in the URL of your stats when you view them on WordPress.com. It’s also in the smiley image URL, the HTML source of your blog, and your database.

    NVM, I found a plugin which does it great here:

    http://wordpress.org/extend/plugins/wp-postviews/

    It adds post Views to the “Custom Area” of a post, if anyone wants help using that plugin let me knew as it’s not completely intuitive.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Grabbing WordPress Statistics Data in the Loop’ is closed to new replies.
Skip to toolbar