Skip to content

Commit

Permalink
Merge pull request #182 from alleyinteractive/feature/args-filters
Browse files Browse the repository at this point in the history
Add filters for query args
  • Loading branch information
dlh01 authored May 20, 2024
2 parents 61d3d3d + dfb550d commit 031196d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `WP Curate` will be documented in this file.

## Unreleased

- Enhancement: Add `wp_curate_plugin_curated_post_query` filter for the arguments used for querying posts that match query block attributes.
- Enhancement: Add `wp_curate_rest_posts_query` filter for the arguments used for querying posts over the REST API for the query block editor preview.
- Enhancement: Make the ID of the post being edited available to `wp_curate_rest_posts_query` filter.

## 1.9.1 - 2024-04-25

- Bug Fix: Improve handling of default post types on the Query block.
Expand Down
1 change: 1 addition & 0 deletions blocks/query/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default function Edit({
status: 'publish',
per_page: 20,
orderby,
current_post_id: Number.isInteger(currentPostId) ? currentPostId : 0,
},
);
path += `&${termQueryArgs}`;
Expand Down
7 changes: 7 additions & 0 deletions src/class-plugin-curated-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public function with_query_context( array $context, array $attributes, WP_Block_
origin: $this->queries,
);

/**
* Filters the arguments used when querying for posts that match the block attributes.
*
* @param array<string, mixed> $args Query arguments.
*/
$args = apply_filters( 'wp_curate_plugin_curated_post_query', $args );

$context['query'] = [
'perPage' => $args['posts_per_page'],
'include' => $queries->query( $args )->post_ids(),
Expand Down
15 changes: 15 additions & 0 deletions src/features/class-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public function register_endpoints(): void {
'methods' => 'GET',
'callback' => [ $this, 'get_posts' ],
'permission_callback' => 'is_user_logged_in',
'args' => [
'current_post_id' => [
'type' => 'integer',
'description' => __( 'The ID of the post being edited, if any.', 'wp-curate' ),
'default' => 0,
],
],
]
);
}
Expand Down Expand Up @@ -128,6 +135,14 @@ function ( $post_type ) use ( $allowed_post_types ) {
$args['tax_query'] = $tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
}

/**
* Filters the REST post query arguments.
*
* @param array<string, mixed> $args The WP_Query arguments.
* @param WP_REST_Request $request The REST request.
*/
$args = apply_filters( 'wp_curate_rest_posts_query', $args, $request );

if ( $trending ) {
/**
* Filters the trending posts query.
Expand Down

0 comments on commit 031196d

Please sign in to comment.