Last active
November 5, 2021 01:28
-
-
Save indikatordesign/069c0b7f363977e092bb5193bdf74133 to your computer and use it in GitHub Desktop.
[Divi - Change the order for the default filterable portfolio module]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this snippet to your themes "functions.php" to order the projects by title | |
add_action( 'parse_query', function( $vars ) | |
{ | |
if ( 'project' == $vars->query['post_type'] ) | |
{ | |
$vars->set( 'orderby', 'title' ); | |
$vars->set( 'order', 'ASC' ); // DESC | |
} // end if | |
}); // end add_action |
The code above works well but will also filter the back end which might be a pain...
This is a quick fix to only sort on the public facing side of the site.
// Order the portfolio items by title
add_action( 'parse_query', function( $vars ) {
if (class_exists("ET_Builder_Module") && 'project' == $vars->query['post_type'] )
{
$vars->set( 'orderby', 'title' );
$vars->set( 'order', 'ASC' );
}
}); // end custom order
Thank you very much!!! This code is amazing, and save my life!!! I was thinking in remake an filterable portfolio with more than 600 entrees or change their dates one by one. The upgrade done by @benjaminlately works perfectly on my site. Thanks again from Caracas Venezuela.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can anyone edit this to filter by slug instead of title?