Shortcode display date
-
Hi hector
i find this shortcode …one good idea
[wpp range=”custom” time_unit=’HOUR’ time_quantity=12 limit =”3″]but for to avoid the action the robot or influencers whose want to click some posts(generaly old)
it’s possible to add in shortcode display only= postdate(“curdate” and 01/01/2018″) or display= postdate :”last365 days”
thanks a lotThe page I need help with: [log in to see the link]
-
Hi @narolles,
There’s already a parameter to have the [wpp] shortcode list posts that were published within a specific time range:
freshness. From the Parameters section (Settings > WordPress Popular Posts):freshness – Tells WordPress Popular Posts to retrieve the most popular entries published within the time range specified by you.
This will display the most viewed posts that where published within the last 12 hours:
[wpp range="custom" time_unit="HOUR" time_quantity=12 limit=3]About your question:
it’s possible to add in shortcode display only= postdate(“curdate” and 01/01/2018″) or display= postdate :”last365 days”
No, I don’t have plans to add this at the moment.
-
This reply was modified 6 years, 6 months ago by
Hector Cabrera. Reason: Answered OP's question about fetching specific dates
thanks a lot for your reactivity
it’s ok with range “weekly” but doesn’t work for “today” ou “custom” “hour” (my example)
my problem is for the display (order views) but not old post (date) (publish date) (more one year for example)
thanks(…) doesn’t work for “today” (…)
todayisn’t a valid time range value. Please check the documentation of therangeparameter via Settings > WordPress Popular Posts > Parameters for the complete list of available time range options.(…) ou “custom” “hour” (my example)
That’s odd. I’ll have a look at the code tomorrow and see what’s going on.
Hello hector
To be precise it is not the range of time (range) to select the articles which poses problem but a range of time whose articles must not appear in the results. In my case limit the display (display) of items older than one year
Currently with
[wpp range = “custom” time_unit = “HOUR” time_quantity = 12 limit = 3]
I have an article of 2019 (ok) – one of 2015 (no ok) and one of 2013 (no ok)
I think for the old is the work of robot or infuencers
thank youPS But I see a change in your previous answers that says you have not planned for the moment
Hi @narolles, good day!
If you want to display the most viewed posts within the last 12 hours that where published within the last 365 days (1 year), adding this to your theme’s
functions.phpfile should do the trick:/** * Filters out popular posts that are older than the * specified time. * * @param string $where * @param array $options * @return string */ function wpp_filter_posts_by_age($where, $options){ if ( ! is_admin() ) { $where .= ' AND p.post_date >= DATE_SUB(NOW(), INTERVAL 1 YEAR) '; } return $where; } add_filter('wpp_query_where', 'wpp_filter_posts_by_age');Note the
INTERVAL 1 YEARpart of the code. This tells WPP to exclude posts that where published over a year ago (365 days) from the current date.Hello Hector
Thanks again for your responsiveness,
My remarks are only constructive and respectful
Concenacting the shortcode
I am not as expert as you ….
What should I add in the shortcode for the filter by age
in function php is ok
Thank youNothing, leave the shortcode as you have it. The PHP code will filter out posts older than a year for you automatically 🙂
in this case the php function does not work
I guess it will be applicable for the whole site?Uncaught ArgumentCountError: Too few arguments to function wpp_filter_posts_by_age(), 1 passed in wp-includes/class-wp-hook.php on line 288 and exactly 2 expected in wp-content/themes/oceanwp-child-theme-master/functions.php:281
Stack trace:
#0 wp-includes/class-wp-hook.php(288): wpp_filter_posts_by_age(‘WHERE 1 = 1 AND…’)
#1 wp-includes/plugin.php(208): WP_Hook->apply_filters(‘WHERE 1 = 1 AND…’, Array)
#2 wp-content/plugins/wordpress-popular-posts/src/Query.php(463): apply_filters(‘wpp_query_where’, ‘WHERE 1 = 1 AND…’, Array)
#3 wp-content/plugins/wordpress-popular-posts/src/Query.php(53): WordPressPopularPosts\Query->build_query()
#4 wp-content/plugins/wordpress-popular-posts/src/Front/Front.php(418): WordPressPopularPosts\Query->__construct(Array)
#5 /home/jarAh, my bad!
Please change:
add_filter('wpp_query_where', 'wpp_filter_posts_by_age');into:
add_filter('wpp_query_where', 'wpp_filter_posts_by_age', 10, 2);Thank you
I made the change
it seems to work,
side backend we see without the filter,
frontend we see with filter
thank you very muchNo problem, glad I could help 🙂
-
This reply was modified 6 years, 6 months ago by
The topic ‘Shortcode display date’ is closed to new replies.