Skip to content

Instantly share code, notes, and snippets.

@guytzhak
Created March 24, 2021 15:30
Show Gist options
  • Save guytzhak/e639985a9488ad44b8e3b2dca20e86fe to your computer and use it in GitHub Desktop.
Save guytzhak/e639985a9488ad44b8e3b2dca20e86fe to your computer and use it in GitHub Desktop.
if ( false === ( $customQuery = get_transient( 'projectName_related_products' ) ) ) {
$args = [
'post_type' => 'post',
];
$customQuery = new WP_Query($args);
set_transient( 'projectName_related_products', $customQuery, 99999 * HOUR_IN_SECONDS );
}
add_action('woocommerce_update_product', function () {
$args = [
'post_type' => 'post',
];
$customQuery = new WP_Query($args);
set_transient( 'projectName_related_products', $customQuery, 99999 * HOUR_IN_SECONDS );
});
if( $customQuery->have_posts() ) {
while ($customQuery->have_posts()) {
$customQuery->the_post();
//your code....
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment