Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #341690

    Hello
    Is is possible to randomize posts that are displayed in the new magazine elements ?
    thanks

    #342609

    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

    #342617

    Hey @Arvish thanks it works :-)
    Is is possible to set a range of date?
    thanks

    #343860

    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

    #343941

    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

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Display Magazine posts in a random order’ is closed to new replies.