Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Plugin Name: MEM Category Order
Plugin URI:
Description: Functionality plugin for
Version: 0.1
Author: Manuel Schmalstieg
Author URI:
* This sample code is written in response to:
* "i would like to use your plugin but is there a way to order all the post of a specific category by the event start date?"
* This example will order posts of the category with slug "events" by their start date.
* Caveat: this Category Archive will now only show articles that have a start date.
function mem_category_order( $query ) {
if ( $query->is_category('events') ) {
$query->set( 'meta_key', '_mem_start_date');
$query->set( 'orderby', 'meta_value');
add_filter( 'pre_get_posts', 'mem_category_order' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.