Code, der nicht alle Produkte einer bestimmten Kategorie durchläuft

Ich versuche, alle Produkte für eine bestimmte Kategorie, die vom Wp E-Commerce-Plugin verwaltet wird, zu holen, aber der Code, den ich verwende, ist nicht alle Produkte zurückgeschleift. Der gesamte Code ist eine Art API, um nach Produkten zu suchen und sie später zu einer externen Anwendung mit JSON zurückzugeben.

Erstens ist das der Code, den ich verwende:

$catid = $_REQUEST['catid'];//get the category id from the url $term1 = get_term($catid,'wpsc_product_category'); getdetails($term1->slug,$term1->term_id,$host,$term1->parent); echo '----------------------------'.'
'; echo $term1->slug .'
'; echo $term1->term_id.'
'; echo $term1->parent.'
'; echo '----------------------------'.'
'; function getdetails($id,$tid,$host,$cid) { $wpec_product_categories = get_terms( 'wpsc_product_category', 'hide_empty=0&slug='.$id); echo '-------this is a stack of the product category array--------
'; var_dump($wpec_product_categories).'
'; echo '-------------------------------------------
'; if($wpec_product_categories[0]->count != 0) { echo 'count is '.$wpec_product_categories[0]->count.'
';//here the correct number of products. So, so far all is going good. foreach($wpec_product_categories as $wpec_categories){ $wpec_term_id = $wpec_categories->term_id; $wpec_term_name = $wpec_categories->name; $wpec_term_slug = $wpec_categories->slug; $wpec_term_parent = $wpec_categories->parent; echo '
--------------------
'; echo $wpec_term_name.'
'; echo $wpec_term_slug.'
'; echo $wpec_term_parent.'
'; echo '
--------------------
'; $wpec_args = array( 'post_status' => 'publish', 'post_type' => 'wpsc-product', 'wpsc_product_category' => $wpec_term_slug ); $wpec_categoryProducts = new WP_Query($wpec_args); while ($wpec_categoryProducts->have_posts()) : $wpec_categoryProducts->the_post(); echo '
---------------------||||||--------------------
'; echo 'Content:'.$wpec_categoryProducts->the_post().'
'; echo '
---------------------||||||--------------------
'; echo 'Product wholesale price: '.wpsc_the_product_price().'
'; $selthumb ="SELECT p.*, pm.* FROM wp_posts as p, wp_postmeta as pm WHERE pm.meta_key = '_thumbnail_id' AND pm.meta_value = p.ID AND p.post_parent = '".wpsc_the_product_id()."' AND p.post_type = 'attachment'"; $resthumb = mysql_query($selthumb); $rowthumb = mysql_fetch_array($resthumb); $img = stripslashes($rowthumb['guid']) ; if($img != '') { $path = $img; } else { $selimg = "SELECT * FROM wp_wpsc_meta WHERE meta_key = 'image' AND object_id = ".$tid; $resimg = mysql_query($selimg); $rowimg = mysql_fetch_array($resimg); if($rowimg != '') { $path = "http://".stripcslashes($host."/wp-content/uploads/wpsc/category_images/".$rowimg['meta_value']); } else { $selimg = "SELECT * FROM wp_wpsc_meta WHERE meta_key = 'image' AND object_id = ".$cid; $resimg = mysql_query($selimg); $rowimg = mysql_fetch_array($resimg); if($rowimg != '') { $path = "http://".stripcslashes($host."/wp-content/uploads/wpsc/category_images/".$rowimg['meta_value']); } else { $selpimg = "SELECT tx.*,m.* FROM wp_term_taxonomy tx,wp_wpsc_meta m WHERE tx.term_id = '".$cid."' AND m.meta_key = 'image' AND m.object_id = tx.parent"; $respimg = mysql_query($selpimg); $rowpimg = mysql_fetch_array($respimg); if($rowpimg != '') { $path = "http://".stripcslashes($host."/wp-content/uploads/wpsc/category_images/".$rowpimg['meta_value']); } else { $path= "false"; } } } } $selcolor = "SELECT * FROM wp_postmeta WHERE post_id = '".wpsc_the_product_id()."' AND meta_key = '_wpsc_color'"; $rescolor = mysql_query($selcolor); $rowcolor = mysql_fetch_array($rescolor); $selsize = "SELECT * FROM wp_postmeta WHERE post_id = '".wpsc_the_product_id()."' AND meta_key = '_wpsc_size'"; $ressize = mysql_query($selsize); $rowsize = mysql_fetch_array($ressize); $selprice = "SELECT * FROM wp_postmeta WHERE post_id = '".wpsc_the_product_id()."' AND meta_key = '_wpsc_special_price'"; $resprice = mysql_query($selprice); $rowprice = mysql_fetch_array($resprice); $selmanu = "SELECT * FROM wp_postmeta WHERE post_id = '".wpsc_the_product_id()."' AND meta_key = '_wpsc_manufacturer'"; $resmanu = mysql_query($selmanu); $rowmenu = mysql_fetch_array($resmanu); $product_data = get_post_custom( wpsc_the_product_id() ); $product_data['meta'] = maybe_unserialize( $product_data ); $image = stripslashes(sb_get_images_for_product( wpsc_the_product_id() )); $list = explode(",",$image); $arr[] = array("Product ID" => wpsc_the_product_id(),"Product Title" => wpsc_the_product_title(), "Product Description" => wpsc_the_product_description(), "Product Wholesale Price" => wpsc_the_product_price(), "Product Sale Price" => '$'.$rowprice['meta_value'], "Category Id" => $wpec_term_id,"Category Name" => $wpec_term_name,"Product Image" => $path, "Product Sub Images" => $list , "SKU" => wpsc_product_sku(), "Quantity" => $product_data['meta']['_wpsc_stock'][0], "Size" => $rowsize['meta_value'], "Color" => $rowcolor['meta_value'], "Manufacturer" => $rowmenu['meta_value'] ); $i++; endwhile; } } }

Ich verstehe nicht, warum foreach und while loop nicht alle Produkte durchlaufen. Sie sind nur die ersten 7-10 Elemente, aber wenn ich die zurückgegebene Anzahl der Produkte überprüfen, sind es rund 60 Elemente. Meine Fragen sind, wie man meinen Code repariert, um über alle Produkte zu schleifen? Bitte helfen Sie und danken Sie im Voraus.

Solutions Collecting From Web of "Code, der nicht alle Produkte einer bestimmten Kategorie durchläuft"

Die Standardanzahl der Posts für WP_Query beträgt zehn Posts pro Seite .

Versuchen Sie, 'posts_per_page' => -1 zu Ihren $wpec_args :

 $wpec_args = array( 'post_status' => 'publish', 'post_type' => 'wpsc-product', 'posts_per_page' => -1, 'wpsc_product_category' => $wpec_term_slug );