Skip to content
Open
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
18 changes: 18 additions & 0 deletions COMMIT_MESSAGE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
feat: Add "Searched Term" filter option to taxonomy-text block

Adds support for displaying the current search term from WordPress search
queries (?s= parameter) in both the standalone taxonomy-text block and the
RichText inline format.

Changes:
- Add "search" to filterType enum in block.json
- Add "Searched Term" option to Filter Source dropdown in editor
- Extract search term from $_GET['s'] or get_query_var('s')
- Decode URL-encoded search terms (e.g., "garden+tools" → "garden tools")
- Hide Value Type and Link controls for search filter (search terms only
support prefix/suffix, no description or link options)
- Update both edit.js (standalone block) and format.js (RichText format)

The search filter will display the searched term when a WordPress search
is active, allowing dynamic display of search queries in content.

32 changes: 32 additions & 0 deletions PR_UPDATE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Added "Searched Term" Filter Option

This update adds support for displaying the current search term from WordPress search queries in the taxonomy-text block and RichText inline format.

### Features

- **New Filter Source**: "Searched Term" option added to the Filter Source dropdown
- **URL Parameter Support**: Extracts search term from `?s=` URL parameter (WordPress native search)
- **URL Decoding**: Automatically decodes URL-encoded search terms (e.g., `garden+tools` → `garden tools`)
- **Prefix/Suffix Support**: Search terms support prefix and suffix text like other filter types
- **Simplified Options**: Search filter hides Value Type and Link controls since search terms don't have descriptions or archive links

### Technical Details

- Added `"search"` to `filterType` enum in `block.json`
- Updated editor components (`edit.js` and `format.js`) to handle search filter type
- Added search term extraction logic in `get_taxonomy_text_result()` function
- Search term is extracted from `$_GET['s']` or `get_query_var('s')` and URL-decoded
- Returns `null` if no search term is present (block won't render)

### Usage

When a user searches on a WordPress site (e.g., `?s=garden+tools`), the taxonomy-text block can now display the searched term dynamically. This is useful for displaying search results context like "Showing results for: garden tools" or similar messaging.

### Files Changed

- `src/taxonomy-text/block.json` - Added "search" to filterType enum
- `src/taxonomy-text/edit.js` - Added search option and UI controls
- `src/taxonomy-text/format.js` - Added search option for RichText format
- `inc/namespace.php` - Added search term extraction logic
- Built assets updated

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Easy to use and lightweight, built using the WordPress Interactivity API.

* Add a query block. This can anyhere that the query block is supported e.g. page, template, or pattern.
* Add one of the filter blocks and configure as required:
* Taxonomy filter. Select which taxonomy to to use, customise the label (and whether it's shown), and customise the text used when none is selected.
* Taxonomy filter. Select which taxonomy to to use, customise the label (and whether it's shown), and customise the text used when none is selected. Optionally enable **Show Terms in Current Results** to limit the dropdown to terms attached to the posts returned by the surrounding query.
* Post type filter. Customise the label (and whether it's shown), as well as the text used when no filter is applied.
* Sort filter. Presents the same ordering options available in the Query Loop block (“Order By”) so visitors can toggle between newest/oldest, alphabetical, menu order, etc. Pick which sort choices appear via checkboxes in the block settings.
* Search block. No extra options.

![image](https://github.com/user-attachments/assets/e2f9b62d-91f7-4c22-87ac-078b4d031a60)
Expand Down
Binary file added build/.DS_Store
Binary file not shown.
73 changes: 73 additions & 0 deletions build/sort/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "query-filter/sort",
"version": "0.1.0",
"title": "Sort Filter",
"category": "theme",
"icon": "sort",
"description": "Allows visitors to change the order of results within a query loop block.",
"ancestor": [
"core/query"
],
"usesContext": [
"queryId",
"query"
],
"supports": {
"html": false,
"className": true,
"customClassName": true,
"color": {
"background": true,
"text": true
},
"typography": {
"fontSize": true,
"textAlign": true,
"lineHeight": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true
}
},
"spacing": {
"margin": true,
"padding": true,
"blockGap": true
},
"interactivity": {
"clientNavigation": true
}
},
"attributes": {
"label": {
"type": "string"
},
"showLabel": {
"type": "boolean",
"default": true
},
"options": {
"type": "object",
"default": {
"date_desc": true,
"date_asc": true,
"title_asc": true,
"title_desc": true,
"comment_desc": true,
"menu_order": true
}
}
},
"textdomain": "query-filter",
"editorScript": "file:./index.js",
"style": "query-filter-view",
"render": "file:./render.php"
}

12 changes: 12 additions & 0 deletions build/sort/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
return [
'dependencies' => [
'wp-block-editor',
'wp-blocks',
'wp-components',
'wp-element',
'wp-i18n',
],
'version' => '1.0.0',
];

155 changes: 155 additions & 0 deletions build/sort/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
( function ( blocks, blockEditor, components, element, i18n ) {
const { registerBlockType } = blocks;
const { InspectorControls, useBlockProps } = blockEditor;
const {
PanelBody,
TextControl,
ToggleControl,
CheckboxControl,
} = components;
const { Fragment, createElement: el } = element;
const { __ } = i18n;

const SORT_OPTIONS = [
{
key: 'date_desc',
label: __( 'Newest to Oldest', 'query-filter' ),
orderby: 'date',
order: 'DESC',
},
{
key: 'date_asc',
label: __( 'Oldest to Newest', 'query-filter' ),
orderby: 'date',
order: 'ASC',
},
{
key: 'title_asc',
label: __( 'A → Z', 'query-filter' ),
orderby: 'title',
order: 'ASC',
},
{
key: 'title_desc',
label: __( 'Z → A', 'query-filter' ),
orderby: 'title',
order: 'DESC',
},
{
key: 'comment_desc',
label: __( 'Most Commented', 'query-filter' ),
orderby: 'comment_count',
order: 'DESC',
},
{
key: 'menu_order',
label: __( 'Menu Order', 'query-filter' ),
orderby: 'menu_order',
order: 'ASC',
},
];

const DEFAULT_OPTIONS = SORT_OPTIONS.reduce( ( acc, option ) => {
acc[ option.key ] = true;
return acc;
}, {} );

registerBlockType( 'query-filter/sort', {
edit( { attributes, setAttributes } ) {
const { label, showLabel = true, options = {} } = attributes;

const resolvedOptions = {
...DEFAULT_OPTIONS,
...options,
};

const enabledOptions = SORT_OPTIONS.filter(
( option ) => resolvedOptions[ option.key ]
);

return el(
Fragment,
null,
el(
InspectorControls,
null,
el(
PanelBody,
{ title: __( 'Sort Settings', 'query-filter' ) },
el( TextControl, {
label: __( 'Label', 'query-filter' ),
value: label,
help: __(
'If empty then no label will be shown',
'query-filter'
),
onChange: ( next ) =>
setAttributes( { label: next } ),
} ),
el( ToggleControl, {
label: __( 'Show Label', 'query-filter' ),
checked: showLabel,
onChange: ( next ) =>
setAttributes( { showLabel: next } ),
} ),
el(
'div',
{ className: 'wp-block-query-filter-sort__options' },
SORT_OPTIONS.map( ( option ) =>
el( CheckboxControl, {
key: option.key,
label: option.label,
checked: resolvedOptions[ option.key ],
onChange: ( next ) =>
setAttributes( {
options: {
...resolvedOptions,
[ option.key ]: next,
},
} ),
} )
)
)
)
),
el(
'div',
useBlockProps( { className: 'wp-block-query-filter' } ),
showLabel &&
el(
'label',
{
className:
'wp-block-query-filter-sort__label wp-block-query-filter__label',
},
label || __( 'Order Results', 'query-filter' )
),
el(
'select',
{
className:
'wp-block-query-filter-sort__select wp-block-query-filter__select',
disabled: true,
},
enabledOptions.map( ( option ) =>
el(
'option',
{
key: option.key,
},
option.label
)
)
)
)
);
},
} );
} )(
window.wp.blocks,
window.wp.blockEditor,
window.wp.components,
window.wp.element,
window.wp.i18n
);

Loading