Last active
May 8, 2018 16:35
-
-
Save ms-studio/b3919690c95daaa1503ea9a949a0767d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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