Tagged: , ,

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #977333

    Hello, I’m new to editing functions.php

    I added this code snipped to the .php file, but it’s just crashing the site when I upload it.
    I have multiple blog pages that have different categories. I’d like them all to be sorted by earliest blog post first. Is there code that will affect this globally instead of each category?

    add_filter(‘avia_blog_post_query’, ‘avia_modify_post_grid_query_desc’);

    function avia_modify_post_grid_query_desc( $query ) {
    if( is_category( ‘japan’ ) ) {
    $query[‘orderby’] = ‘title’;
    $query[‘order’] = ‘DESC’;
    return $query;
    }
    }

    • This topic was modified 6 years, 1 month ago by prospanicatc.
    #977476

    Hey Andrew,

    Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?

    Can you please check server log for error?

    Best regards,
    Victoria

    #977775

    Hi Victoria
    Is that the password to bluehost or the site itsef

    #978031

    Hi prospanicatc,

    Credentials did not work for me. Could you please update the credentials?

    Best regards,
    Victoria

    #978073

    Sorry about that

    #979635

    Hi,

    The login credentials still didn’t work for me. However please try to add this code to the child theme functions.php file to change the post order globally:

    
    add_filter('avia_blog_post_query', 'avia_modify_post_grid_query_desc', 10);
    function avia_modify_post_grid_query_desc( $query ) {
    if( !empty($query) ) {
    $query['orderby'] = 'date';
    $query['order'] = 'ASC';
    }
    return $query;
    }
    

    You can replace ASC with DESC to revert the order. 

    Best regards,
    Dude

    #981022

    Ok I know this username and password work, I just tested it out myself.
    How do I do it so the main blog page shows the latest one at the top, but other pages such as http://loosyourselfabroad.com/blog/japan-2017/ are sorted descending?

    #981747

    Hi,

    Now I could log in but the account does not have admin rights (so we can’t edit pages,  access the theme editor, etc.)

    If you just want to change the sort order on pages which are not used as the home/front page or your main blog (http://loosyourselfabroad.com/blog/) you can try this code:

    
    add_filter('avia_blog_post_query', 'avia_modify_post_grid_query_desc', 10);
    function avia_modify_post_grid_query_desc( $query ) {
    if(!empty($query) && !is_home() && !is_front_page() && !is_page('2')) {
    $query['orderby'] = 'date';
    $query['order'] = 'DESC';
    }
    return $query;
    }
    

    Best regards,
    Dude

    #981814

    Shoot sorry about that. Fixed the permissions. Where do I put this query?

    #982326

    Hi,

    Please try it at the bottom of your functions.php file.

    Best regards,
    Rikard

    #982438

    That worked beautifully thank you

    #982560

    Hi prospanicatc,

    Glad we could help :)

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.