How To Change The Order Of Projects In The Divi Portfolio Module Tutorial By Pee Aye Creative

How To Change The Order Of Projects In The Divi Portfolio Module

Our tutorial today will show you how to change the order of projects in the Divi Portfolio module alphabetically or randomly.

Join subscribers on our YouTube channel and enjoy other Divi video tutorials!

Add A PHP Code Snippet

The tutorial only requires one simple step, which involves pasting the PHP code snippet below into your website. There are a number of locations to add this, and it will totally depend on your website and experience.

If you have a child theme, then you would add this snippet to the functions.php file of a Divi child theme. If you don’t already have one, you can download our free Divi child theme here.

If you want the easy way, then I will recommend installing the Code Snippets plugin. It is a great plugin that allows you to add snippets easily in the backend of your admin area. After activating, just go to Snippets>Add New, write a title, paste the snippet, and click the save and activate button. Here is how that will look:

PHP snippet to change the order of the Divi Projects in the Portfolio module

PHP Snippet - Order Alphabetically By Title

add_filter('et_pb_module_shortcode_attributes', 'add_pre_get_portfolio_projects', 10, 3);
add_filter('et_pb_portfolio_shortcode_output', 'remove_pre_get_portfolio_projects');

function add_pre_get_portfolio_projects($props, $atts, $slug) {
$portfolio_module_slugs = array('et_pb_portfolio', 'et_pb_filterable_portfolio', 'et_pb_fullwidth_portfolio');
	if (!in_array($slug, $portfolio_module_slugs)) {
		return $props;
	}
	add_action('pre_get_posts', 'do_portfolio_pre_get_posts');

	return $props;
}

function do_portfolio_pre_get_posts($query) {
		
	do_action('pre_get_portfolio_projects', $query);
}
function remove_pre_get_portfolio_projects($content) {
	
	remove_action('pre_get_posts', 'do_portfolio_pre_get_posts');
	return $content;
}

//order projects by title

add_action('pre_get_portfolio_projects', 'pa_change_portfolio_module_order');
function pa_change_portfolio_module_order($query) {	
	$query->set('orderby', 'title');
$query->set('order', 'ASC');
}

Reverse The Order Z-A

If for some reason you want to show the items in the opposite order, you can edit the “ASC” in the code snippet. Simply replace the ASC with DESC the the items will show from Z to A.

Change Order To Random

You can also show the projects in Portfolio module in random order. For that, we will use the main part of the first snippet and only change the last part following the comment //order projects by title. So to make the order random, paste the above snippet, then remove the part after the // comment. In its place, paste the snippet below. Please watch the video above to see this in action, as it is important to get it correct.

Replacement PHP Snippet - Order Randomly

//order projects randomly

add_action('pre_get_portfolio_projects','pa_random_portfolio_module_order');

function pa_random_portfolio_module_order($query) {	

	$query->set('orderby', 'rand'); 
 }
1

Last updated Jul 18, 2022 @ 4:53 pm

Subscribe

Each month we send out a roundup email newsletter with the latest tutorials, product updates, helpful resources, and any other industry or personal news. Occasionally we send an extra separate email here and there if we just can’t wait! So that’s what you will get if you subscribe, and you can always unsubscribe at any time if you just can’t take it anymore :)

Please share this post!

Nelson Lee Miller (aka The Divi Teacher)

Nelson is the owner of Pee-Aye Creative in the beautiful state of Pennsylvania. He loves helping small businesses, exploring outdoors, building websites with Divi, and teaching others.

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy

2 Comments

Submit a Comment

Your email address will not be published.

Recent Posts

Pin It on Pinterest

0

Your Cart