Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sort-by Widget Extension
<?php
/*
Plugin Name: Sort-by Extension
Plugin URI: http://tiptoppress.com/downloads/term-and-category-based-posts-widget/
Description: Extension 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
*/
namespace termCategoryPostsPro\SortByExtension;
// 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, $this, $instance ) {
if ($query_args['orderby'] == 'name' || $query_args['orderby'] == 'title')
$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, $this, $instance ) {
$byName = array(
'name' => 'Name (Slug)',
'title' => 'Title');
$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