Last active
June 26, 2017 10:52
-
-
Save damiencarbery/c6ed32e81a32e80964895f9dda00d03f to your computer and use it in GitHub Desktop.
Using Post Meta instead of Transients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Use transients. | |
if ( false === ( $transient_data = get_transient( 'transient_name' ) ) ) { | |
// Regenerate transient. | |
} | |
// Use post meta. | |
if ( false === ( $post_meta_data = get_post_meta(1, 'post_meta_name', true ) ) ) { | |
// Regenerate post meta. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Query all products and only retrieve post IDs | |
$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); | |
$product_ids = array(); | |
$product_ids = $products_query->posts; // This is the 'loop'! | |
wp_reset_postdata(); | |
foreach ($product_ids as $id) { | |
// Do stuff | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pq_args = array( | |
'post_type' => 'product', | |
'posts_per_page' => -1, | |
'no_found_rows' => true, | |
'update_post_term_cache' => false, | |
'update_post_meta_cache' => false, | |
); | |
$products_query = new WP_Query($pq_args); | |
if ( $products_query->have_posts() ) { | |
while ( $products_query->have_posts() ) { | |
$products_query->the_post(); | |
// Do stuff | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment