The next version of Index is here! To celebrate, take 25% off your purchase with the code 25OFF. Learn more
Index Logo

Sorting filters

Ordering filters using the registration hook is almost impossible due to the ability to call those hooks in any plugin, at any time. This resource separates the sort order and registration logic. All registered filters are included before this resource is fired.

Modifying the sort order

Each sort order is tied to a specific post type:

// replace {$type} with the post type name
add_filter("index_{$type}_order_filters", function($filters) {
    return $filters;
});

Sort order options

The $filters parameter in the hook is a simple array of all smart filter ids. The global $Index class includes four methods for sorting which abstract complex PHP array sorting and also verify the item exists in the current list (if not, it ignores the update):

placeFirst

Places the field at the beginning of the list:

$Index->placeFirst(
	$filters, // array of all filter ids
	'date'    // filter id to move
);

placeLast

Places the field at the end of the list:

$Index->placeLast(
	$filters, // array of all filter ids
	'date'    // filter id to move
);

placeAt

Places the filter at a specific position in the list (note this is only advised if you know exactly what you’re doing):

$Index->placeAt(
	$fields, // array of all filter ids 
	2,       // new position
	'date'   // filter id to move
);

placeAfter

Places the filter after another one, if they both exist:

$Index->placeAfter(
	$filters, // array of all filter ids 
	'title',  // anchor filter id
	'date'    // filter id to move
);

Example

add_filter('index_post_order_filters', function($filters) {
	global $Index;
	
	$Index->placeAfter(
		$filter,
		'status',
		'date'
	);

	return $filters;
});

Resources

Get started with Index

See for yourself why Index is the most intuitive, beautiful interface for managing your WordPress content.