最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - Save large WP_Query to transient === false

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论