Skip to content

Feature Request: Add setting to exclude posts that have been on the most-viewed list for a certain duration #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
grantbarrett opened this issue Mar 17, 2025 · 11 comments
Milestone

Comments

@grantbarrett
Copy link

Is your feature request related to a problem? Please describe.

Would it be possible to add a setting to allow exclusion of posts that have appeared in the top lists for a certain amount of time?

Describe the solution you'd like

Some kind of option in the shortcode to use the WPP logs to track if a post has been in the top lists in a way that meets the plugin's current criteria and then give the user the option of not displaying it. For example, if I have a new "items of the week" article every week I might want to make them not display in the top posts lists after seven days but also not want to have to keep editing my shortcode to add more article IDs to exclude every week.

If post meets current settings X and post has met those criteria for period of time Z then don't display post for period of time Q.

@cabrerahector
Copy link
Owner

Hi @grantbarrett,

Thanks for the suggestion! I got one better (?), how about for example adding new time range options, like:

  • Current day
  • Current week
  • Current Month

That way your popular posts list will only pull data from eg. the current week, completely ignoring past data. That way, once the selected "current X" time range ends the next one will automatically only list items that are being viewed / commented on within the new time range. With this, you won't need to manually exclude IDs each week.

...hope I managed to explain myself, it makes sense in my head but it's Sunday night here and my brain is not in the freshest state right now haha 😅

@grantbarrett
Copy link
Author

That would be less processor-intensive, for sure! I think that would be an elegant solution to my situation.

@cabrerahector
Copy link
Owner

Alright, I may create a separate branch to implement this functionality and ask you to test it out for me if that's OK. I'll let you know, no ETA though but hopefully soon.

@cabrerahector
Copy link
Owner

Alright, took a little while but I just pushed a new branch called this-x-time-ranges that implements new time ranges as stated on this comment.

Branch: https://github.com/cabrerahector/wordpress-popular-posts/tree/feature/this-x-time-ranges
PR: #395

Please give them a try and let me know if you have any comments/questions @grantbarrett

@grantbarrett
Copy link
Author

I will check it out!

@grantbarrett
Copy link
Author

Can you give guidance on how to test it with the shortcode? That's how I implement it. Thanks! @cabrerahector

@cabrerahector
Copy link
Owner

Ah, forgot to mention that haha @grantbarrett

With this change, the range parameter now accepts the following values: today, thisweek and thismonth.

For example:

[wpp header='Popular Today' range='today']
[wpp header='Popular This Week' range='thisweek']
[wpp header='Popular This Month' range='thismonth']

As to how to get the actual plugin with these changes:

  1. Optional but highly recommended, create a full backup of your site (files and database.)
  2. Go to the time-x-ranges branch.
  3. Click on the green Code button near the top of the page.
  4. Click on the Download Zip button to download the plugin in .zip format and extract it into your desktop in its own folder (eg. wordpress-popular-posts-feature-this-x-time-ranges). This is so there's no conflict with the regular WordPress Popular Posts plugin that's currently installed on your site.
  5. Delete the zip file as it's no longer needed.
  6. Open wordpress-popular-posts-feature-this-x-time-ranges\wordpress-popular-posts.php with a text editor (or a code editor if you use one) and change Plugin Name: to something like WordPress Popular Posts, New Time Ranges Version and save changes.
  7. Delete the wordpress-popular-posts-feature-this-x-time-ranges\uninstall.php file, this is so when you're done testing you can safely delete this dev version of the plugin without losing any popular posts data.
  8. Create a new zip file from the wordpress-popular-posts-feature-this-x-time-ranges folder (or whatever you called it :P)
  9. Go to your site > Plugins.
  10. Deactivate WordPress Popular Posts (do not uninstall it, just disable it.)
  11. Click on the Upload Plugin button at the top of the page, select the zip file you just created and follow the on-screen instructions to activate it.

Once you're done testing:

  1. Please share your feedback here.
  2. Disable and then delete the dev version of the plugin.
  3. Reactivate the regular WordPress Popular Posts plugin.

@grantbarrett
Copy link
Author

grantbarrett commented May 1, 2025

Thanks! That displays posts!

It is acting counter to expectations, however. I am using [wpp limit='6' range='thismonth' order_by='views' post_type='post' post_html='<li><a href="{url}" alt="{title_attr}" target="_blank">{title}</a></li>'] and it is showing posts from 2021 and 2012. They may have been updated this month (usually with things like tags) but they were first published long ago. I assume there is an internal modified date in WordPress the plugin is using that is not exposed in the dashboard; I would think it should use the published date that the WP control panel shows.

Also, can we get a thisyear in there? So many things are annual.

@cabrerahector
Copy link
Owner

Yes, that shortcode will display the most viewed posts of this month regardless of their publication date.

If you want it to only list the most viewed posts that were also published within the current month use the freshness parameter (although that might need adjustment, I'm not sure if it'll work with the new time range options now that I think about it, I'll have a look at it later.)

[wpp limit='6' range='thismonth' freshness=1 order_by='views' post_type='post' post_html='<li><a href="{url}" alt="{title_attr}" target="_blank">{title}</a></li>']

@grantbarrett
Copy link
Author

Oh, see. I guess I kind of lost sight of what we were doing here. Sorry! I will look into freshness.

@cabrerahector
Copy link
Owner

Don't worry about it, it's fine.

I'll look into adding a thisyear option, shouldn't be too much of an issue and I'm sure other people will want to have it too so it makes sense.

About some settings not being exposed on the Stats dashboard, someone already made a request to include them in #273 - I just keep forgetting about it (ᵕ・ᴗ・)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants