Producten in bulk verwijderen (WordPress PHP-API)
Probeersel (mei 2019)
Ik ben er bijna, maar ik krijg get_pages
nog niet aan de praat (project rt.ww):
############################################################### # dvb_delete_all_products ############################################################### # # get_pages doet 't niet ################################################ function dvb_delete_all_products() { $arg = array ( 'post_type' => 'product' ); $products = get_pages(); print_r($products); // $myproducts = get_pages( array( 'post_type' => 'products') ); // print_r($myproducts); // foreach ( $myproducts as $myproduct ) // { // # Display post-IDs // ####################################### // # // echo "Post-ID: ".$myproduct->ID."\n"; // # Delete all products // ####################################### // # // # Set to False to move to Trash // # // wp_delete_post( $myproduct->ID, true); // } }
Probeersel (2)
Het begin is er - Ik kan alleen geen vertalingen verwijderen. Die verschijnen niet
<?php # # Get all products and/or images ############################################################### # print "\n===================================================\n"; print "===================================================\n"; print "===================================================\n"; ############################################################### # Libraries ############################################################### # $pad = "/home/strompf/www/rt.dvb/"; require_once($pad . "wp-load.php"); # These libraries seem not to be needed ####################################### # # require_once($pad . 'wp-admin/includes/media.php'); # require_once($pad . 'wp-admin/includes/file.php'); # require_once($pad . 'wp-admin/includes/image.php'); ############################################################### # get_pages - Wrong function ############################################################### # // $pages = get_pages(); // print_r($pages); ############################################################### # get_pages - Wrong function ############################################################### # # Appearantly, products are not "pages" in the sense of this # function - You just don't get them! # // $args = array // ( // 'post_type' => 'product' // ); // $pages = get_pages($args); // print_r($pages); ############################################################### # get_posts - Prints only Dutch products! ############################################################### # # * The trick is, that if you don't specify otherwise, some # default values are in place, like # # * 'post_type' => 'page' # * 'numberposts' => 72 # # * I still only get 23 products - Exactly all Dutch products # but no translations # // $args = array // ( // 'numberposts' => 72, // 'post_type' => 'product' // ); // $products = get_posts( $args ); // print_r($products); ############################################################### # Delete! ############################################################### # // $args = array // ( // 'numberposts' => 1000, // 'post_type' => 'product' // ); // $products = get_posts( $args ); // print_r($products); // $i=0; // foreach ($products as $product) // { // $i++; // echo $i." Post-ID: ".$product->ID."\n"; // wp_delete_post($product->ID, true); // } ############################################################### # get_posts - Get translations - Not working ############################################################### # $args = array ( 'numberposts' => -1, 'post_type' => 'product', 'category' => 1 ); $products = get_posts( $args ); $i=0; foreach ($products as $product) { $i++; echo $i." Post-ID: ".$product->ID."\n"; }