Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sort-by menu-order Add-on
<?php
/*
Plugin Name: Sort-by menu_order Add-on
Plugin URI: http://tiptoppress.com/downloads/term-and-category-based-posts-widget/
Description: Add-on to add more sort possibilities for the premium widget Term and Category Based Posts Widget.
Author: TipTopPress
Version: 0.1
Author URI: http://tiptoppress.com
Installation:
A.) Manual / with a FTP client
- Download the file and rename it to Sort-by-menu-order-add-on.php
- Upload it to the plugins folder [your-wordpress-installation]/wp-content/plugins/sort-by-menu-order-add-on.php
B.) With Plugins admin
- Downlaod the file as ZIP
- Go to Plugins > Install > Upload and select the ZIP file
... than:
- Go to WordPress > Admin > PlugIns and activate the Extension
- Now, there is a new sort by: 'Menu_order' visible
- We recommend to use the menu_order Add-on in conjunction with re-order widgets like:
+ - https://wordpress.org/plugins/simple-page-ordering/,
+ - https://wordpress.org/plugins/metronet-reorder-posts/ or
+ - https://de.wordpress.org/plugins/post-types-order/
*/
namespace termCategoryPostsPro\SortByMenuOrderAddon;
// Don't call the file directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Applied to the list of sort orders some new ones.
*
* @return array of sort orders
*
* @since 0.1
*/
function query_args ( $query_args, $that, $instance ) {
if ($query_args['orderby'] == 'menu_order')
$query_args['order'] = 'ASC';
return $query_args;
}
add_filter( 'cpwp_query_args', __NAMESPACE__.'\query_args', 10, 3 );
/**
* Applied to the list of sort orders some new ones.
*
* @return array of sort orders
*
* @since 0.1
*/
function possible_sorts ( $sorts, $that, $instance ) {
$byName = array(
'menu_order' => 'Menu_order');
$sorts = array_merge ($byName, $sorts);
return $sorts;
}
add_filter( 'cpwp_possible_sorts', __NAMESPACE__.'\possible_sorts', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment