Hello
Is is possible to randomize posts that are displayed in the new magazine elements ?
thanks
Hi pako69!
Line 366 in (theme folder)/config-templatebuilder/avia-shortcodes/magazine.php
Change the following:
$query = array( 'orderby' => 'date',
To this:
$query = array( 'orderby' => 'rand',
Note that this will be overwritten upon a theme update. Please make a note of this change during updates.
Regards,
Arvish
Hey @Arvish thanks it works :-)
Is is possible to set a range of date?
thanks
Hey!
No, unfortunately, it’s not possible to specify data range. Instead of modifying the magazine.php file, please add this on functions.php:
add_filter('avf_magazine_entries_query', 'avf_magazine_entries_custom_query');
function avf_magazine_entries_custom_query ( $query ) {
$query['orderby'] = 'rand';
$query['order'] = 'DESC';
return $query;
}
Refer to the wp codex for more order and orderby parameters.
Best regards,
Ismael
Hello @Ismael
Great :-) Better than modifiying Enfold core files.
I’ve found some tricks that can do what I want :
RANDOM AND POST FROM THE CURRENT MONTH :
add_filter('avf_magazine_entries_query', 'avf_magazine_entries_custom_query');
function avf_magazine_entries_custom_query ( $query ) {
$query['orderby'] = 'rand';
$query['order'] = 'DESC';
$current_month = date('m');
$query['monthnum'] = $current_month;
return $query;
RANDOM AND POSTS FROM THE LAST 5 WEEKS
add_filter('avf_magazine_entries_query', 'avf_magazine_entries_custom_query');
function avf_magazine_entries_custom_query ( $query ) {
$query['orderby'] = 'rand';
$query['order'] = 'DESC';
$query['date_query'] = array(
array(
'after' => '5 week ago'
)
);
return $query;
}
With the help of :
https://tommcfarlin.com/get-posts-from-last-week/
and
http://codex.wordpress.org/Class_Reference/WP_Query#Date_Parameters