Save large WP_Query to transient === false

I try to save a WP_Query to a transient but it's always comes back false dispite the fact that the transient is saved.

Here is the code:

$fitsToTransientName = 'g_wc_fits_to_' . get_the_ID();
$fitsToTransient = get_transient($fitsToTransientName);

if (false === $fitsToTransient) {
    echo Test;

    $argsFits = array(
        'post_type'         = 'product',
        'no_found_rows'     = true,
        'posts_per_page'    = -1,
        'meta_query' = array(
            array(
                'key' = 'accessories',
                'value' = '' . get_the_ID() . '',
                'compare' = 'LIKE'
            )
        )
    );

    $fitsToTransient = new WP_Query($argsFits);
    
    set_transient($fitsToTransientName, $fitsToTransient, DAY_IN_SECONDS);
}

$queryFitsTo = $fitsToTransient;

if ($queryFitsTo-have_posts()) { ... // And here goes the loop

Here what I know:

  • The line Test always echos witch tells me that the $fitsToTransient always is false
  • If I var_dump $fitsToTransient it's always just: false
  • If I use WP Cli and search for the transient, I can clearly see that it's there and har the full query stored correctly.
  • Query Monitor does not tell me that there has been a new transient saved (exept for the first time when it's aqually created).

I've run out of things to try out now and was hoping anyone has any good ideas why it's always false and how to fix it.

Topic woocommerce-offtopic transient wp-query cache Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.