WordPress.org

Ready to get started?Download WordPress

Forums

for each $post???? cache data for each post daily (2 posts)

  1. ext103
    Member
    Posted 3 years ago #

    hello all,

    im working on a plugin right now that uses seostats class to gather pr,backlinks, etc for each post/page.

    it then displays them on the list of posts/pages page in the admin panel so you can see stats for each post/page.

    this is simple enough. but causes some serious speed issues, obviously due to checking the stats for each post in one page request.

    what i need is a way to "cache" or store this data and only run the stats request once a day.

    i think this can be achived by doing a foreach and saving the data as post_meta and runnign this function using wordpress built in cron functions.

    the only problem is i havent seen anyhting like this before and no idea how to start.

    any help would be greatly apreciated.

  2. ext103
    Member
    Posted 3 years ago #

    okay, i think ive figured some of it out, but now have another problem. first heres the code i am using to get it working (sort of)

    function seop_update_page_stats(){
    global $post;
    $args = array( 'post_type' => 'page' );
    $myposts = get_posts($args);
    foreach( $myposts as $post ) {
    setup_postdata($post);
    $id = $post->ID;
    $result = stuff i do to get the data
    update_post_meta($id, 'seop_stats', $result);
    }
    }

    so this code sort of works (i also have the same function for the "posts" page type), i can set this up to run off the wordpress cron.

    problem is this only seems to do some of the posts. i dont this as a timeout either as it doing some old post, and some new ones, but it doesnt seem to update all posts.

    has anyone every had anything similar?

Topic Closed

This topic has been closed to new replies.

About this Topic