Skip to content

Instantly share code, notes, and snippets.

@indikatordesign
Last active November 5, 2021 01:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save indikatordesign/069c0b7f363977e092bb5193bdf74133 to your computer and use it in GitHub Desktop.
Save indikatordesign/069c0b7f363977e092bb5193bdf74133 to your computer and use it in GitHub Desktop.
[Divi - Change the order for the default filterable portfolio module]
<?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
@jan1980
Copy link

jan1980 commented Aug 18, 2018

That was excellent thanks...!

@guidoeffe
Copy link

Thanks a lot!
It's simple but magic...

@constmoon
Copy link

This is really a life saver…

@metrosuperstar
Copy link

metrosuperstar commented Mar 11, 2019

To the author: thank you! This is very helpful. However, what would the code look like if we wanted to target 2 different portfolio modules according to their class name in Divi? (because the other would be sorted by last modified, instead of title).
I'm assuming that if(class_exists("")){ needs to be used - but my syntax didn't work.

@OvidiuZeicu
Copy link

Thank you very much, it worked great for quite a while. Unfortunately, since Divi 4.0 (or around that version) it no longer works and crashes the website. Something along the lines: "Website is experiencing a PHP error", after I removed this code everything was working again, but I could not add it again in the theme editor, saving fails, sometimes with an "Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP." error, but lately with "Your PHP code changes were rolled back due to an error on line 578 of file wp-includes/functions.php. Please fix and try saving again. Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)" error.
That 578 line is part of a function for "Unserialize value only if it was serialized.".
I'm pretty sure all it needs it's a small adjustment in the function to work again, but PHP is not something I have skills in. Could you look into it, please?

@dgrimey
Copy link

dgrimey commented Feb 3, 2020

Thanks for posting. Saved me a ton of time with one quick Google search.

@brandylynn02
Copy link

Can anyone edit this to filter by slug instead of title?

@benjaminlately
Copy link

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

@tecnologiasos
Copy link

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