php - Wordpress get_posts() fetch next batch of posts -


i'm using get_posts() function fetch batch of posts custom post type, sorted id, modify posts , fetch next batch.

i have following code:

<?php require_once('wp-load.php'); $temp_list_of_products_array        = get_posts( array('post_type' => 'sale', 'numberposts' => 10 ) ); $temp_list_of_products_array_length = count( $temp_list_of_products_array );  ($xt = 0; $xt < $temp_list_of_products_array_length; $xt++) {     $temp_product_id                    = $temp_list_of_products_array[$xt]->id;     $temp_product_untranslated_field    = get_post_meta($temp_product_id, 'wpcf-product-details', true);     $temp_product_translated_field      = get_post_meta($temp_product_id, 'wpcf-translated-product-details', true);     $temp_product_description_language  = 'en';      if ($temp_product_translated_field == null) {         $temp_product_translated_contents   = google_translate_text($temp_product_untranslated_field, $temp_product_description_language);         update_post_meta($temp_product_id, 'wpcf-translated-product-details', $temp_product_translated_contents);     }      echo $temp_product_id; } ?> 

this works great problem loads first 10 posts ordered date.

my question is, how next batch of 10 posts without have user activated pagination call?

thanks

first current page

$paged=($query_vars['paged']!=0 ? $query_vars['paged'] : 1); 

now calculate offset value

$numberposts=10; $ofdset=$numberposts* ($paged - 1) ; 

add code

$temp_list_of_products_array = get_posts( array('post_type' => 'sale', 'numberposts' => 10 ,'offset'=>$offset) ); $temp_list_of_products_array_length = count( $temp_list_of_products_array );  ($xt = 0; $xt < $temp_list_of_products_array_length; $xt++) {     $temp_product_id                    = $temp_list_of_products_array[$xt]->id;     $temp_product_untranslated_field    = get_post_meta($temp_product_id, 'wpcf-product-details', true);     $temp_product_translated_field      = get_post_meta($temp_product_id, 'wpcf-translated-product-details', true);     $temp_product_description_language  = 'en';      if ($temp_product_translated_field == null) {         $temp_product_translated_contents   = google_translate_text($temp_product_untranslated_field, $temp_product_description_language);         update_post_meta($temp_product_id, 'wpcf-translated-product-details', $temp_product_translated_contents);     }      echo $temp_product_id; } 

add pagination code @ bottom of loop check wordpress pagination get_posts function https://wordpress.stackexchange.com/questions/137100/using-pagination-with-get-posts-on-page-type


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -