Loosen order and orderby restrictions
This allows more options for shortcodes.
This commit is contained in:
parent
6482bb689d
commit
52e8d4c662
@ -8,12 +8,13 @@
|
||||
* Returns list of allowed orderby parameters for WP_Query
|
||||
*
|
||||
* @since 5.7.0
|
||||
* @since 5.9.4 - Extended list.
|
||||
*
|
||||
* @return array List of allowed orderby parameters.
|
||||
*/
|
||||
|
||||
function fictioneer_allowed_orderby() {
|
||||
$defaults = ['modified', 'date', 'title', 'rand'];
|
||||
$defaults = ['modified', 'date', 'title', 'rand', 'name', 'ID', 'comment_count', 'type', 'post__in', 'author'];
|
||||
|
||||
return apply_filters( 'fictioneer_filter_allowed_orderby', $defaults );
|
||||
}
|
||||
|
@ -157,23 +157,14 @@ function fictioneer_get_default_shortcode_args( $attr, $def_count = -1 ) {
|
||||
$attr = is_array( $attr ) ?
|
||||
array_map( 'sanitize_text_field', $attr ) : sanitize_text_field( $attr );
|
||||
|
||||
//--- Setup ------------------------------------------------------------------
|
||||
|
||||
$order = [sanitize_key( $attr['order'] ?? 'desc' )];
|
||||
$order = array_intersect( $order, ['desc', 'asc'] );
|
||||
$order = reset( $order ) ?: 'desc';
|
||||
$orderby = [sanitize_key( $attr['orderby'] ?? 'date' )];
|
||||
$orderby = array_intersect( $orderby, fictioneer_allowed_orderby() );
|
||||
$orderby = reset( $orderby ) ?: 'modified';
|
||||
|
||||
//--- Extract arguments ------------------------------------------------------
|
||||
|
||||
$args = array(
|
||||
'type' => $attr['type'] ?? 'default',
|
||||
'count' => max( -1, intval( $attr['count'] ?? $def_count ) ),
|
||||
'offset' => max( 0, intval( $attr['offset'] ?? 0 ) ),
|
||||
'order' => $order,
|
||||
'orderby' => $orderby,
|
||||
'order' => $attr['order'] ?? '',
|
||||
'orderby' => $attr['orderby'] ?? '',
|
||||
'page' => max( 1, get_query_var( 'page' ) ?: get_query_var( 'paged' ) ),
|
||||
'posts_per_page' => absint( $attr['per_page'] ?? 0 ) ?: get_option( 'posts_per_page' ),
|
||||
'post_ids' => fictioneer_explode_list( $attr['post_ids'] ?? '' ),
|
||||
|
Loading…
x
Reference in New Issue
Block a user