Skip to content

Commit aa11748

Browse files
committed
[Pro] setting: feed_category_slugs
Also fixes bug where daily popular feeds gave a 404 error.
1 parent 7555027 commit aa11748

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

includes/admin/settings/class-settings.php

+14
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,19 @@ public static function settings_feed() {
10641064
'min' => '0',
10651065
'size' => 'small',
10661066
),
1067+
'feed_category_slugs' => array(
1068+
'id' => 'feed_category_slugs',
1069+
'name' => esc_html__( 'Filter Categories', 'top-10' ),
1070+
'desc' => esc_html__( 'Comma separated list of category slugs to include in the feed. The field has an autocomplete so simply start typing the starting letters and it will prompt you with options. Leave blank to include all categories.', 'top-10' ),
1071+
'type' => 'csv',
1072+
'options' => '',
1073+
'size' => 'large',
1074+
'field_class' => 'category_autocomplete',
1075+
'field_attributes' => array(
1076+
'data-wp-taxonomy' => 'category',
1077+
),
1078+
'pro' => true,
1079+
),
10671080
);
10681081

10691082
/**
@@ -1395,6 +1408,7 @@ public function change_settings_on_save( $settings ) {
13951408

13961409
Settings_Sanitize::sanitize_tax_slugs( $settings, 'exclude_cat_slugs', 'exclude_categories' );
13971410
Settings_Sanitize::sanitize_tax_slugs( $settings, 'exclude_on_cat_slugs', 'exclude_on_categories' );
1411+
Settings_Sanitize::sanitize_tax_slugs( $settings, 'feed_category_slugs', 'feed_categories' );
13981412

13991413
// Save cron settings.
14001414
$settings['cron_hour'] = min( 23, absint( $settings['cron_hour'] ) );

includes/frontend/class-feed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function pop_posts_feed() {
4343
add_feed( $popular_posts_overall, array( $this, 'pop_posts_feed_overall' ) );
4444
}
4545
if ( ! empty( $popular_posts_daily ) ) {
46-
add_feed( $popular_posts_overall, array( $this, 'pop_posts_feed_daily' ) );
46+
add_feed( $popular_posts_daily, array( $this, 'pop_posts_feed_daily' ) );
4747
}
4848
}
4949

includes/frontend/feed-rss2-popular-posts.php

+14-12
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
'daily_range' => tptn_get_option( 'feed_daily_range' ),
1111
'limit' => tptn_get_option( 'feed_limit' ),
1212
);
13-
$topposts = get_tptn_posts( $settings );
1413

15-
$topposts = wp_list_pluck( (array) $topposts, 'postnumber' );
16-
17-
$args = array(
18-
'post__in' => $topposts,
19-
'orderby' => 'post__in',
20-
'posts_per_page' => count( $topposts ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
21-
);
14+
/**
15+
* Filter the RSS feed settings.
16+
*
17+
* @since 4.1.0
18+
*
19+
* @param array $settings Array of RSS feed settings.
20+
*/
21+
$settings = apply_filters( 'tptn_rss_feed_settings', $settings );
2222

23-
query_posts( $args ); // phpcs:ignore WordPress.WP.DiscouragedFunctions.query_posts_query_posts
23+
// Initialize Top_Ten_Query with our settings.
24+
$query = new Top_Ten_Query( $settings );
2425

2526
header( 'Content-Type: ' . feed_content_type( 'rss2' ) . '; charset=' . get_option( 'blog_charset' ), true );
2627
$more = 1; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
@@ -55,7 +56,7 @@
5556
>
5657

5758
<channel>
58-
<title><?php wp_title_rss(); ?></title>
59+
<title><?php wp_title_rss(); ?> <?php esc_html_e( 'Popular Posts', 'top-10' ); ?> - <?php echo esc_html( $settings['daily'] ? sprintf( _n( 'Last %d day', 'Last %d days', $settings['daily_range'], 'top-10' ), $settings['daily_range'] ) : __( 'Overall', 'top-10' ) ); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment ?></title>
5960
<atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
6061
<link><?php bloginfo_rss( 'url' ); ?></link>
6162
<description><?php bloginfo_rss( 'description' ); ?></description>
@@ -99,8 +100,8 @@
99100
*/
100101
do_action( 'rss2_head' );
101102

102-
while ( have_posts() ) :
103-
the_post();
103+
while ( $query->have_posts() ) :
104+
$query->the_post();
104105
?>
105106
<item>
106107
<title><?php the_title_rss(); ?></title>
@@ -139,5 +140,6 @@
139140
?>
140141
</item>
141142
<?php endwhile; ?>
143+
<?php wp_reset_postdata(); ?>
142144
</channel>
143145
</rss>

readme.txt

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Top 10 also has powerful API and is fully extendable with WordPress actions and
5555
* **Custom Display Options**
5656
- **Taxonomy-Specific Displays**: Use the `display_only_on_tax_ids` parameter to restrict popular post displays to specific taxonomy terms.
5757
- **Category Inclusion**: Include popular posts from specific categories using a new option in the Edit Post meta box.
58+
- **RSS Feed Filtering**: Enhanced RSS feeds with category and post type filtering, available via URL parameters (?category=news, ?post_type=product) and dedicated settings.
5859

5960
* **Enhanced Tracking and Performance**
6061
- **Fast Tracker**: A new, faster tracking method to improve post view speed.
@@ -155,6 +156,7 @@ When you enabled the scheduled maintenance, Top 10 will create a cron job that w
155156
* Features:
156157
* Import data from the WordPress Popular Posts plugin.
157158
* [Pro] Query Optimization: Add MySQL MAX_EXECUTION_TIME directive to prevent long-running queries from consuming excessive server resources. Configurable via settings and the `top_ten_query_max_execution_time` filter.
159+
* [Pro] Enhanced Popular Posts RSS feeds with category and post type filtering, available via URL parameters and configurable via dedicated settings.
158160
* Admin Dashboard:
159161
* Smart chart visualization: Automatically switches to an area chart for datasets with more than 100 data points.
160162
* [Pro] Clicking on a column in the Popular Posts chart will display the most popular posts for the selected day.

0 commit comments

Comments
 (0)