Skip to content

Instantly share code, notes, and snippets.

@gabcarvalhogama
Created December 16, 2023 14:47
Show Gist options
  • Save gabcarvalhogama/37033a5ecda69bff22116aac899b3e31 to your computer and use it in GitHub Desktop.
Save gabcarvalhogama/37033a5ecda69bff22116aac899b3e31 to your computer and use it in GitHub Desktop.
<?php
/**
* Update the posts widget or portfolio widget query.
*
* @since 1.0.0
* @param \WP_Query $query The WordPress query instance.
*/
function custom_query_callback( $query ) {
// Obter a data de início da semana anterior
$start_of_last_week = strtotime('last monday', strtotime('-1 week'));
// Obter a data de término da semana anterior
$end_of_last_week = strtotime('next sunday', $start_of_last_week) + 86399; // 86399 segundos em um dia
// Modificar a query para o widget de postagens mais lidos
$query->set('meta_key', 'post_views_count');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'DESC');
$query->set('date_query', array(
array(
'after' => date('Y-m-d', $start_of_last_week),
'before' => date('Y-m-d', $end_of_last_week),
'inclusive' => true,
),
));
}
add_action( 'elementor/query/posts_maislidos', 'custom_query_callback' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment