Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/c6ed32e81a32e80964895f9dda00d03f to your computer and use it in GitHub Desktop.
Save damiencarbery/c6ed32e81a32e80964895f9dda00d03f to your computer and use it in GitHub Desktop.
Using Post Meta instead of Transients
<?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.
}
<?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
}
<?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