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 am working on plugin which will work automatically via wordpress schedule hooks. But to do that I need a single record from database and process it and next schedule run, I want to get next single record from database to process.

I am using custom table for my data, the table have a primary key with auto increment value.

So how can I get next record every time when wordpress schedule hook runs ?

I have tried with sessions/php pagination and Its working outside of wordpress but wordpress does not provide session support so I can't use it. I can use $wpdb global class for single record retrieval but I don't have a idea about next record retrieval.

I hope I have explained my problem clearly.

here is the function which will execute on wp schedule hook:

function ACP_poster($n){
        global $wpdb,$api_key;
        $row = $wpdb->get_results('SELECT a,b,c FROM tbname ORDER BY id DESC LIMIT 1',ARRAY_A);

        $url = 'https://example.com';

        $headers = array( 'Authorization' => $api_key );
        $request = new WP_Http;
        $result = $request->request( $url , array( 'method' => 'GET', 'headers' => $headers, 'sslverify' => false ) );
        $data = new SimpleXMLElement($result['body']);
        $attributes = $data->p->attributes();

        foreach ($data->p[0] as $p) 
                // Sanitize data.
                $pr = number_format((float)$p->pr, 2, '.', ' ');
                $image = '<a href="'.$p->{'url2'}.'"><img src="'.$p->{'url3'}                            .'" style="float: right"/></a>';
                $pd =  $image.$p->description .'-- ='.$p->currency.' '.
                       ' ,Retail Price ='.$p->{'retail-price'}.' , '.
                       $p->{'sale-price'}.'<a href="'.$p->{'url2'}.
                $v = $c[$no]->child;
                $ids = get_term_by('slug', $v, 'category');//wordpress function

                $id = (int)$ids->term_taxonomy_id;
                $p2 = array('post_title'    => $p->name,
                    'post_content'  => $pd,
                    'post_status'   => 'publish',
                    'post_author'   => 1,
                    'post_category'  =>array($id));
                $pr = wp_insert_post( $p2, $wp_error );

                wp_reset_query();  // Restore global post data stomped by the_post().
share|improve this question
WHERE id > {$someotherid} ORDER BY id DESC LIMIT 1... but this is not a WordPress question unless there is more to it than that. –  s_ha_dum Nov 9 '13 at 16:04

Your Answer


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

Browse other questions tagged or ask your own question.