Hello everyone and thank you for taking a look.
What i wish to do is load all my products on one page in order to export them in an xml file.
My problem is not with the xml code but with loading all the products part.
My website has 13.419 products.
Here is my code:
//Get The Number Of Products
$count_posts = wp_count_posts( 'product' ); //Get all Products
$number_of_posts = $count_posts->publish; //Get only the published ones
//Divide them into pages
$number_of_pages = $number_of_posts / 9; //Dividing them by 9 thats its going to be per page
$number_of_pages_rounded = round($number_of_pages, 0); //Rounding up for the loop
//Create Numbers For showing lines and Pages
$mynumber = 1;
$my_number_2 = 1;
//Just Echoing
echo 'Totla Posts: ' . $number_of_posts . '<br>';
echo 'Total Pages: ' . $number_of_pages_rounded .'<br>';
echo '<br>';
echo "<br> ======1===== <br><br>";
//Page Loop
for($i == 0; $i < $number_of_pages_rounded; $i++) {
//Query Arguments
$args3 = array(
'posts_per_page' => 9,
'post_type' => 'product',
'post_status' => 'publish',
'paged' => $my_number_2,
);
//Query
$loop = new WP_Query( $args3 );
//Product Loop
if ( $loop->have_posts() ){
while ( $loop->have_posts() ){
$loop->the_post();
global $product;
echo $mynumber .') ' .$product->id.'<br>';
echo '-----------'.'<br>';
$mynumber++;
}
//wp_reset_postdata();
}
$my_number_2++;
echo "<br> ======$my_number_2===== <br><br>";
}
//Just to stop the rest of the site to load
die;
I don’t get it, what am i doing wrong?
Here is a gif about the result:
https://ibb.co/WvqxY8j
What is the best way to archive what i want to do?
2
Answers
So after the great answer from "Martin Mirchev" i took everything i wanted from the database directly on the plus side i saved a ton of memory, here is my code: (I am posting it so anyone who has the same idea can find it)
I would love if someone could give me feedback if i am doing something wrong. Thanks
Add following function in your functions.php file in your active theme.