Add filters for RSS query args
This commit is contained in:
parent
42367f0ae2
commit
36aac5bd3e
37
FILTERS.md
37
FILTERS.md
@ -1421,6 +1421,43 @@ Filters the RSS link returned by the `fictioneer_get_rss_link( $post_type, $post
|
||||
|
||||
---
|
||||
|
||||
### `apply_filters( 'fictioneer_filter_rss_main_query_args', $query_args )`
|
||||
Filters the query arguments for the main RSS feed in the `rss-rss-main.php` template.
|
||||
|
||||
**Parameters:**
|
||||
* $query_args (array) – Associative array of query arguments.
|
||||
|
||||
**Example:**
|
||||
```php
|
||||
function child_exclude_protected_posts_from_main_rss( $query_args ) {
|
||||
$query_args['has_password'] = false;
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
add_filter( 'fictioneer_filter_rss_story_query_args', 'child_exclude_protected_posts_from_main_rss' );
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `apply_filters( 'fictioneer_filter_rss_story_query_args', $query_args, $story_id )`
|
||||
Filters the query arguments for the story RSS feed in the `rss-rss-story.php` template.
|
||||
|
||||
**Parameters:**
|
||||
* $query_args (array) – Associative array of query arguments.
|
||||
* $story_id (int) – Post ID of the story.
|
||||
|
||||
**Example:**
|
||||
```php
|
||||
function child_exclude_protected_posts_from_story_rss( $query_args ) {
|
||||
$query_args['has_password'] = false;
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
add_filter( 'fictioneer_filter_rss_story_query_args', 'child_exclude_protected_posts_from_story_rss' );
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `apply_filters( 'fictioneer_filter_safe_title', $title, $post_id, $context, $args )`
|
||||
Filters the string returned by the `fictioneer_get_safe_title( $post_id )` function, after all tags and line breaks have been stripped. No further sanitization is applied here, so you can add HTML again.
|
||||
|
||||
|
@ -8,22 +8,25 @@
|
||||
* @link https://github.com/WordPress/WordPress/blob/master/wp-includes/feed-rss2.php
|
||||
*/
|
||||
|
||||
// Query posts
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'fictioneer_query_name' => 'main_rss',
|
||||
'post_type' => ['post', 'fcn_story', 'fcn_chapter', 'fcn_recommendation'],
|
||||
'post_status' => 'publish',
|
||||
'ignore_sticky_posts' => 1,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'posts_per_page' => get_option( 'posts_per_rss' ) + 8, // Buffer in case of invalid results
|
||||
'update_post_meta_cache' => true,
|
||||
'update_post_term_cache' => true,
|
||||
'no_found_rows' => true
|
||||
)
|
||||
|
||||
// Query
|
||||
$query_args = array(
|
||||
'fictioneer_query_name' => 'main_rss',
|
||||
'post_type' => ['post', 'fcn_story', 'fcn_chapter', 'fcn_recommendation'],
|
||||
'post_status' => 'publish',
|
||||
'ignore_sticky_posts' => 1,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'posts_per_page' => get_option( 'posts_per_rss' ) + 8, // Buffer in case of invalid results
|
||||
'update_post_meta_cache' => true,
|
||||
'update_post_term_cache' => true,
|
||||
'no_found_rows' => true // Improve performance
|
||||
);
|
||||
|
||||
$query_args = apply_filters( 'fictioneer_filter_rss_main_query_args', $query_args );
|
||||
|
||||
$posts = get_posts( $query_args );
|
||||
|
||||
// Filter out hidden posts (faster than meta query)
|
||||
$posts = array_filter( $posts, function ( $post ) {
|
||||
// Chapter hidden?
|
||||
|
@ -13,6 +13,7 @@
|
||||
* @link https://github.com/WordPress/WordPress/blob/master/wp-includes/feed-rss2.php
|
||||
*/
|
||||
|
||||
|
||||
// Get ID from parameter
|
||||
$story_id = fictioneer_validate_id( $_GET[ 'story_id' ] ?? 0, 'fcn_story' );
|
||||
$is_hidden = get_post_meta( $story_id ?: 0, 'fictioneer_story_hidden', true );
|
||||
@ -142,6 +143,8 @@ do_action( 'rss_tag_pre', 'rss2' );
|
||||
'no_found_rows' => true // Improve performance
|
||||
);
|
||||
|
||||
$query_args = apply_filters( 'fictioneer_filter_rss_story_query_args', $query_args, $story_id );
|
||||
|
||||
$chapter_query = new WP_Query( $query_args );
|
||||
|
||||
// Loop over chapters
|
||||
|
Loading…
x
Reference in New Issue
Block a user