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

    Is is possible to add a condition to the function below that would allow for filtering of one category chronologically and 1 alphabetically?

    Dude/Peter helped me with this code in functions file to change default sorting to alphabetical however I need some categories output to be chronological….

    add_filter(‘avia_post_slide_query’,’avia_order_by_random’, 10, 2);
    function avia_order_by_random($query, $params)
    {
    $query['orderby'] = ‘title’;
    $query['order'] = ‘ASC’;
    return $query;
    }
    Thank you for your help!

    #217750

    Hey ttem!

    You can try following code

    
    
    add_filter('avia_post_slide_query','avia_order_by_random', 10, 2);
    function avia_order_by_random($query, $params)
    {
    $query['orderby'] = 'title';
    $query['order'] = 'ASC';
    
    $terms = explode(',', $params['categories']);
    if (!empty($terms) && in_array(55, $terms)) 
    {
        $query['orderby'] = 'date';
    }
    return $query;
    }
    

    and replace 55 with the id of the category you want to sort chronological.

    Best regards,
    Peter

    #218290

    Big Thanks Peter works great!

    I added
    $query['order'] = 'DESC';
    so most recent posts show first.

    Is it possible to specify multiple categories to sort by date:

    if (!empty($terms) && in_array(55, $terms))
    I tried adding another category id like below but that doesn’t seem to work
    if (!empty($terms) && in_array(55,56, $terms))

    Any idea how to aply the sorting to multiple categories in that function?

    Thank you for your help!

    #218347

    Hey!

    Please replace it with this:

    add_filter('avia_post_slide_query','avia_order_by_random', 10, 2);
    function avia_order_by_random($query, $params)
    {
    $query['orderby'] = 'title';
    $query['order'] = 'ASC';
    
    $terms = explode(',', $params['categories']);
    if (!empty($terms) && in_array(55, $terms)) 
    {
        $query['orderby'] = 'date';
    }
    
    if (!empty($terms) && in_array(56, $terms)) 
    {
        $query['orderby'] = 'date';
    }
    return $query;
    }

    Best regards,
    Ismael

    #223707

    Thank you again Ismael!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Blog grid: How to sort/display 1 category chronologically and 1 alphabetically?’ is closed to new replies.