如何在elementor中获取随机帖子每10分钟旋转一次的

时间:2019-10-22 17:35:19

标签: wordpress elementor

我正在使用elementor / astra,并且尝试设置随机的帖子,该帖子每10分钟自动旋转一次,并且也具有自定义的帖子字段循环。帖子小部件确实具有随机帖子,但不执行查询的时间部分。我已经尝试过以下子主题的functions.php中的自定义代码,但是它不起作用。

是否有某种方法可以实现它以使其与elementor一起使用?

我试图在functions.php的子主题中添加随机/时间php代码 我宁愿不使用插件,但希望它与具有自定义字段类型的post小部件一起工作。我假设我需要在代码中添加一些东西来定位循环?

我确实尝试了一个插件,但是它并没有满足我的要求,因为我需要已经设计好的帖子小部件来旋转。

function force_random_day_seed($orderby) {
        $seed = floor(time()/(60*10*1));
        $orderby=str_replace('RAND()', "RAND({$seed})", $orderby);
        return $orderby;
    }
            add_filter('posts_orderby', 'force_random_day_seed');
$temp_value = get_option(current_time('Y-m-d'));
if($temp_value == '' ){
    $args = array('numberposts' => 3, 'orderby' => 'rand', 'post_type' => 'properties');
    $totd = get_posts($args);
foreach($totd as $k=>$v){
update_option(current_time('Y-m-d'),$v->ID);
}
}else{
$totd = get_posts($temp_value);
}
    remove_filter('posts_orderby', 'force_random_day_seed');
    foreach( $totd as $post ) : ?> 
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endforeach; ?>

我希望随机帖子每10分钟旋转一次,但只有在帖子小部件设置为random时,它才会在刷新时随机化。

0 个答案:

没有答案