WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Grabbing WordPress Statistics Data in the Loop (11 posts)

  1. JordashTalon
    Member
    Posted 4 years ago #

    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

  2. MichaelH
    Member
    Posted 4 years ago #

    Might have to write your own, but here's the structure of the data
    http://stats.wordpress.com/csv.php

  3. Andy Skelton
    Member
    Posted 4 years ago #

    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.

  4. JordashTalon
    Member
    Posted 4 years ago #

    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.

  5. MichaelH
    Member
    Posted 4 years ago #

    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

  6. JordashTalon
    Member
    Posted 4 years ago #

    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?

  7. MichaelH
    Member
    Posted 4 years ago #

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

  8. JordashTalon
    Member
    Posted 4 years ago #

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

  9. MichaelH
    Member
    Posted 4 years ago #

    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.

  10. Andy Skelton
    Member
    Posted 4 years ago #

    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.

  11. JordashTalon
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags