Support » Plugin: WordPress Popular Posts » Maximum page views

  • Resolved alex856

    (@alex856)


    Hello Hector,

    thank you very much for this fantastic plugin. Is it possible to make an additional setting in the widget so that only posts with a maximum of 1500 views are displayed? The 25 postings that had the most views in the last 30 days, but not more than 1500 views, should be included. Thank you for your help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Héctor Cabrera

    (@hcabrera)

    Hi @alex856,

    This feature is something that only a handful of people would use IMO and so I’m not too convinced that it should be added to the plugin. An add-on plugin (or even a simple PHP code snippet) can do the job but -again- it’s not something I would add to WPP.

    If you’re a developer, have a look at the Query class. You’ll find some filter hooks in there that you can use to filter posts by the max. number of pageviews.

    Thread Starter alex856

    (@alex856)

    Hello Héctor,

    many thanks for your response. Unfortunately I am not a developer. How can I filter that exactly? Many thanks.

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Hey Alex,

    I’m flooded with work at the moment (this time of the year is usually a busy one for us developers), if you don’t mind waiting for a bit I can lend you a hand with this. How long that wait will be I don’t know but hopefully not too long.

    If this is something urgent though then you may want to consider hiring a developer instead so they can get this done for you ASAP (if you do hire one please let me know in advance so I don’t invest time in this.)

    Thread Starter alex856

    (@alex856)

    Hello Héctor,

    thank you. I can wait. Thank you for your help.

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Hi @alex856,

    Alright so this code should do what you’re looking for. Add it to your theme’s functions.php file (or to a site-specific plugin) and you should be good to go:

    /**
     * Modifies WPP's database query so it returns 
     * only popular posts that have up to 1,500 views.
     *
     * @param string $where
     * @param array $options
     * @return string $where
     */
    function wpp_limit_max_views($where, $options) {
        if ( ! is_admin() ) {
            $where .= ' AND pageviews <= 1500 ';
        }
        return $where;
    }
    add_filter('wpp_query_where', 'wpp_limit_max_views', 10, 2);

    Note that if you’re using the Data Caching feature you’ll need to temporarily disable it, save changes, then enable it back (and save changes) for this code to take effect. Otherwise you’ll need to wait for the cached data to expire for WPP to run this code.

    Please let me know if you have any questions, alright?

    Thread Starter alex856

    (@alex856)

    Hi Héctor,

    thank you, it works.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Maximum page views’ is closed to new replies.