I need to change order at "all courses" page. Default it's by date, i need to make it lower to higer price. Which hook i need to use? I tried few but im total newbie and nothing works. Thanks for help and ur time.
My Answer:
You can use the `pre_get_posts` hook to modify the query for the courses on the "all courses" page in Learnpress. Here's an example code snippet that you can add to your theme's functions.php file:
php
function custom_course_order( $query ) {
if ( is_post_type_archive( 'lp_course' ) && $query->is_main_query() ) {
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'meta_key', '_lp_price' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'custom_course_order' );
This code will modify the query to order the courses by the price in ascending order. Just paste this code in your theme's functions.php file and the courses should now be ordered by price on the "all courses" page.
Rate this post
3 of 5 based on 9244 votesComments