Skip to content

Commit

Permalink
Merge branch 'trunk' into feature/last-date-range
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwelcher committed Jun 21, 2024
2 parents 7b051f5 + 54b6b11 commit e4cfbed
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 54 deletions.
2 changes: 0 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ template: |
categories:
- title: '🚀 Features'
collapse-after: 3
label: 'enhancement'
- title: '🐛 Bug Fixes'
collapse-after: 3
labels:
- 'fix'
- 'bugfix'
Expand Down
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
5 changes: 4 additions & 1 deletion src/components/post-date-query-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export const PostDateQueryControls = ( { attributes, setAttributes } ) => {
value={ relationFromQuery }
disabled={ range !== '' }
options={ [
{ label: __( 'None', 'advanced-query-loop' ), value: '' },
{
label: __( 'None', 'advanced-query-loop' ),
value: '',
},
{
label: __( 'Before', 'advanced-query-loop' ),
value: 'before',
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
50 changes: 49 additions & 1 deletion src/variations/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { addFilter } from '@wordpress/hooks';
import { InspectorControls } from '@wordpress/block-editor';
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -92,4 +93,51 @@ const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => {
return <BlockEdit { ...props } />;
};

addFilter( 'editor.BlockEdit', 'core/query', withAdvancedQueryControls );
addFilter(
'editor.BlockEdit',
'aql/add-add-controls/core/query',
withAdvancedQueryControls
);

/**
* Filter to add AQL transform to core/query block
*
* @param {Object} settings
* @param {string} name
* @return {Object} settings
*/
function addAQLTransforms( settings, name ) {
if ( name !== 'core/query' ) {
return settings;
}

return {
...settings,
keywords: [ ...settings.keywords, 'AQL', 'aql' ],
transforms: {
to: settings?.transforms?.to || [],
from: [
...( settings?.transforms?.from || [] ),
{
type: 'enter',
regExp: /^(AQL|aql)$/,
transform: () => {
return createBlock(
'core/query',
{
namespace: 'advanced-query-loop',
},
[]
);
},
},
],
},
};
}

addFilter(
'blocks.registerBlockType',
'aql/add-transforms/query-block',
addAQLTransforms
);

0 comments on commit e4cfbed

Please sign in to comment.