Skip to content

Instantly share code, notes, and snippets.

@ms-studio
Last active May 8, 2018 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms-studio/b3919690c95daaa1503ea9a949a0767d to your computer and use it in GitHub Desktop.
Save ms-studio/b3919690c95daaa1503ea9a949a0767d to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: MEM Category Order
Plugin URI: https://gist.github.com/
Description: Functionality plugin for https://wordpress.org/support/topic/ordering-post/.
Version: 0.1
Author: Manuel Schmalstieg
Author URI: https://ms-studio.net
*/
/**
* This sample code is written in response to:
*
* https://wordpress.org/support/topic/ordering-post/
*
* "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