Title: Shortcode display date
Last modified: November 3, 2019

---

# Shortcode display date

 *  Resolved [NAROLLES](https://wordpress.org/support/users/narolles/)
 * (@narolles)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/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 lot
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fshortcode-display-date%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12092722)
 * Hi [@narolles](https://wordpress.org/support/users/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](https://wordpress.org/support/users/hcabrera/).
      Reason: Answered OP's question about fetching specific dates
 *  Thread Starter [NAROLLES](https://wordpress.org/support/users/narolles/)
 * (@narolles)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12092751)
 * 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
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12092764)
 * > (…) doesn’t work for “today” (…)
 * `today` isn’t a valid time range value. Please check the documentation of the`
   range` parameter 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.
 *  Thread Starter [NAROLLES](https://wordpress.org/support/users/narolles/)
 * (@narolles)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12093357)
 * 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 you
 * PS But I see a change in your previous answers that says you have not planned
   for the moment
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12094840)
 * Hi [@narolles](https://wordpress.org/support/users/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.
   php` file 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 YEAR` part of the code. This tells WPP to exclude posts 
   that where published over a year ago (365 days) from the current date.
 *  Thread Starter [NAROLLES](https://wordpress.org/support/users/narolles/)
 * (@narolles)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12095554)
 * 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 you
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12095572)
 * Nothing, leave the shortcode as you have it. The PHP code will filter out posts
   older than a year for you automatically 🙂
 *  Thread Starter [NAROLLES](https://wordpress.org/support/users/narolles/)
 * (@narolles)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12095655)
 * 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/jar
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12095775)
 * Ah, 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);`
 *  Thread Starter [NAROLLES](https://wordpress.org/support/users/narolles/)
 * (@narolles)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12096025)
 * 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 much
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12096032)
 * No problem, glad I could help 🙂

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Shortcode display date’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

## Tags

 * [range](https://wordpress.org/support/topic-tag/range/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [time](https://wordpress.org/support/topic-tag/time/)

 * 11 replies
 * 2 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/shortcode-display-date/#post-12096032)
 * Status: resolved