I created a logic inside my WordPress, where for every CPT shop_oder, there is a post_meta called "luck_number". The problem is that on average, each post in this CPT has had more than 1000 sales, and then when I create a while to go through and get the post_meta with get_post_meta, the page takes about 15 minutes to load, specifically inside the While do loop.
I did a test, and when there are few post_meta the speed is ok, but when we get to the thousand place, it gets pretty slow.
What would be the best way, so that even in this scenario of thousands of post_meta per POST, I still have a good performance?
The section where the laugh is like this:
<?php
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$numbers = get_post_meta(get_the_ID(),"luck_number",false);
$a = 0;
while($a<count($numbers)):
// DO SOMETHING WITH THE NUMBER
$a++;
endwhile;
endwhile;
wp_reset_query();
While each post has an average of 0 to 500 numbers, everything works fine. Above 1000, it's very slow.
My 'post_per_page' averages 25, but even changing it to a smaller number doesn't change the result much. The infrastructure like the server (a good VPS) or the memory_limit of PHP (currently with 1024M) hasn't interfered much