• Resolved George

    (@quantum_leap)


    Hi there. I am using a theme that has an option on the backend to sort articles in the frontend by published date. Is there a way to trick the theme into sorting the articles in the frontend with the modified date instead?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Sayan Datta

    (@infosatech)

    Which theme you are using?

    Thread Starter George

    (@quantum_leap)

    It’s one from ThemeForest, it’s a knowledgebase theme:
    https://themeforest.net/item/knowhow-a-knowledge-base-wordpress-theme/2813111

    There is an option on the theme panel settings to select from 3 different sorting options:

    View post on imgur.com

    Plugin Author Sayan Datta

    (@infosatech)

    Hi @quantum_leap, actually this is not my plugin’s part. This plugin only shows the last modified date and time on both backend and frontend. So I can’t help you with this issue. Please contact with theme support.

    Thanks!

    Thread Starter George

    (@quantum_leap)

    Had no luck with the theme author as usual! Can I modify my question a bit? Is it possible to replace the default WordPress sort date functionality with the modified date instead? I am talking independent of any theme. So instead of WordPress sorting posts in the frontend by date (ascending or descending) to sort by modified date instead?

    Plugin Author Sayan Datta

    (@infosatech)

    Hi George, paste this snippet at the end of your theme’s functions.php file.

    function lmt_orderby_modified_posts( $query ) {
        if( $query->is_main_query() && !is_admin() ) {
    	if ( $query->is_home() || $query->is_category() || $query->is_tag() ) {
                $query->set( 'orderby', 'modified' );
                $query->set( 'order', 'desc' );
    	}
        }
    }
    add_action( 'pre_get_posts', 'lmt_orderby_modified_posts' );

    Hope, this will fulfil your need. Thanks.

    Thread Starter George

    (@quantum_leap)

    That’s just brilliant! In my case, it seems that the query had been modified so it wasn’t the main query anymore, so I changed the code to:

    function lmt_orderby_modified_posts( $query ) {
        if( !is_main_query() && !is_admin() ) {
    	if ( $query->is_home() || $query->is_category() || $query->is_tag() ) {
                $query->set( 'orderby', 'modified' );
                $query->set( 'order', 'desc' );
    	}
        }
    }
    add_action( 'pre_get_posts', 'lmt_orderby_modified_posts' );

    Thanks again!

    I also want my updated blog posts to show on the top of my blog list on the frontend. It would be nice if it would also update my RSS feed too but that might be a different topic.

    I posted the code above to my functions.php file and refreshed my page. It didn’t see to work. Any ideas? Thanks!

    Plugin Author Sayan Datta

    (@infosatech)

    Hi @lorirow

    Which snippet you are using?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Sort posts by modified date in the frontend’ is closed to new replies.