Advertisement
daymobrew

WordPress - large products query failing

Jun 15th, 2016
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!-- $Id: $ -->
  3. <html lang="en-US">
  4. <head>
  5. <meta charset="UTF-8" />
  6. <title>Set Locations transient</title>
  7. <meta name="viewport" content="width=device-width, initial-scale=1" />
  8. </head>
  9. <body>
  10. <h1>Set Locations Transient</h1>
  11. <?php
  12. // Set the value of the 'bdd-locations-count' transient.
  13.  
  14. define('WP_USE_THEMES', false);
  15.  
  16. /** Loads the WordPress Environment and Template */
  17. require( dirname( __FILE__ ) . '/../wp-blog-header.php' );
  18.  
  19.  
  20. $args = array('post_type'=>'product', 'posts_per_page' => -1, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false);
  21. $products_query = new WP_Query($args);
  22.  
  23. $locations = array();
  24. $i = 0;
  25. if ( $products_query->have_posts() ) {
  26.     while ( $products_query->have_posts() ) {
  27.         $products_query->the_post();
  28.         $i++;
  29.         $regions = get_field('region', get_the_ID());
  30.         if ($regions != false) {
  31.             foreach ($regions as $region) {
  32.                 if (isset($locations[$region])) {
  33.                     $locations[$region]++;
  34.                 }
  35.                 else {
  36.                     $locations[$region] = 1;
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
  42. echo '<!-- Transient regenerated -->';
  43. wp_reset_postdata();
  44. //set_transient('bdd-locations-count', $locations, DAY_IN_SECONDS);
  45. update_post_meta(1, 'bdd-locations-count', $locations);
  46. echo "Examined $i products.\n";  
  47. ?>
  48. </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement