Tagged: sort by
I’m currently using this code, which works well.
add_filter('avia_blog_post_query', 'avia_modify_post_grid_query_asc');
function avia_modify_post_grid_query_asc( $query ) {
$query['orderby'] = 'title';
$query['order'] = 'ASC';
return $query;
}
However, I only want it on a specific page or module on a page.
Is this possible?
Hey Jad,
Thank you for the inquiry.
You can use the is_page conditional function to exclude the other pages and apply the changes to a specific page.
// https://developer.wordpress.org/reference/functions/is_page/
Example:
function avia_modify_post_grid_query_asc( $query ) {
if(is_page(123)) {
$query['orderby'] = 'title';
$query['order'] = 'ASC';
}
return $query;
}
add_filter('avia_blog_post_query', 'avia_modify_post_grid_query_asc');
The filter above will only change the query on the page with the ID 123.
Best regards,
Ismael