Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds sorting by Name #71

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion includes/query-loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function ( $pre_render, $parsed_block ) {
'query_loop_block_query_vars',
function ( $default_query, $block ) {
// Retrieve the query from the passed block context.
$block_query = $block->context['query'] ?? [];
$block_query = $block->context['query'] ?? array();

// Process all of the params
$qpg = new Query_Params_Generator( $default_query, $block_query );
Expand Down Expand Up @@ -127,6 +127,7 @@ function add_more_sort_by( $query_params ) {
$query_params['orderby']['enum'][] = 'rand';
$query_params['orderby']['enum'][] = 'post__in';
$query_params['orderby']['enum'][] = 'comment_count';
$query_params['orderby']['enum'][] = 'name';
return $query_params;
}

Expand Down
103 changes: 54 additions & 49 deletions src/components/post-order-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,57 @@
import { SelectControl, ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

export const sortOptions = [
{
label: __( 'Name', 'advanced-query-loop' ),
value: 'name',
},
{
label: __( 'Author', 'advanced-query-loop' ),
value: 'author',
},
{
label: __( 'Comment Count', 'advanced-query-loop' ),
value: 'comment_count',
},
{
label: __( 'Date', 'advanced-query-loop' ),
value: 'date',
},
{
label: __( 'Included Posts', 'advanced-query-loop' ),
value: 'post__in',
},
{
label: __( 'Last Modified Date', 'advanced-query-loop' ),
value: 'modified',
},
{
label: __( 'Menu Order', 'advanced-query-loop' ),
value: 'menu_order',
},
{
label: __( 'Meta Value', 'advanced-query-loop' ),
value: 'meta_value',
},
{
label: __( 'Meta Value Num', 'advanced-query-loop' ),
value: 'meta_value_num',
},
{
label: __( 'Post ID', 'advanced-query-loop' ),
value: 'id',
},
{
label: __( 'Random', 'advanced-query-loop' ),
value: 'rand',
},
{
label: __( 'Title', 'advanced-query-loop' ),
value: 'title',
},
];

/**
* PostOrderControls component
*
Expand All @@ -25,55 +76,9 @@ export const PostOrderControls = ( { attributes, setAttributes } ) => {
)
: ''
}
options={ [
{
label: __( 'Author', 'advanced-query-loop' ),
value: 'author',
},
{
label: __( 'Comment Count', 'advanced-query-loop' ),
value: 'comment_count',
},
{
label: __( 'Date', 'advanced-query-loop' ),
value: 'date',
},
{
label: __( 'Included Posts', 'advanced-query-loop' ),
value: 'post__in',
},
{
label: __(
'Last Modified Date',
'advanced-query-loop'
),
value: 'modified',
},
{
label: __( 'Menu Order', 'advanced-query-loop' ),
value: 'menu_order',
},
{
label: __( 'Meta Value', 'advanced-query-loop' ),
value: 'meta_value',
},
{
label: __( 'Meta Value Num', 'advanced-query-loop' ),
value: 'meta_value_num',
},
{
label: __( 'Post ID', 'advanced-query-loop' ),
value: 'id',
},
{
label: __( 'Random', 'advanced-query-loop' ),
value: 'rand',
},
{
label: __( 'Title', 'advanced-query-loop' ),
value: 'title',
},
] }
options={ sortOptions.sort( ( a, b ) =>
a.label.localeCompare( b.label )
) }
onChange={ ( newOrderBy ) => {
setAttributes( {
query: {
Expand Down
Loading