Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!-- $Id: $ -->
- <html lang="en-US">
- <head>
- <meta charset="UTF-8" />
- <title>Set Locations transient</title>
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- </head>
- <body>
- <h1>Set Locations Transient</h1>
- <?php
- // Set the value of the 'bdd-locations-count' transient.
- define('WP_USE_THEMES', false);
- /** Loads the WordPress Environment and Template */
- require( dirname( __FILE__ ) . '/../wp-blog-header.php' );
- $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);
- $products_query = new WP_Query($args);
- $locations = array();
- $i = 0;
- if ( $products_query->have_posts() ) {
- while ( $products_query->have_posts() ) {
- $products_query->the_post();
- $i++;
- $regions = get_field('region', get_the_ID());
- if ($regions != false) {
- foreach ($regions as $region) {
- if (isset($locations[$region])) {
- $locations[$region]++;
- }
- else {
- $locations[$region] = 1;
- }
- }
- }
- }
- }
- echo '<!-- Transient regenerated -->';
- wp_reset_postdata();
- //set_transient('bdd-locations-count', $locations, DAY_IN_SECONDS);
- update_post_meta(1, 'bdd-locations-count', $locations);
- echo "Examined $i products.\n";
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement