Created
December 16, 2023 14:47
-
-
Save gabcarvalhogama/37033a5ecda69bff22116aac899b3e31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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