• Resolved Rami

    (@rami4625)


    Hello,
    I want to ask how I can exclude post from showing in the best week views if it showing in the best month views?

    I use the code for week views :
    <?php
    if ( function_exists(‘wpp_get_mostpopular’) ) {
    wpp_get_mostpopular(array(
    ‘limit’ => 5,
    ‘range’ => ‘last7days’,
    ‘order_by’ => ‘views’,
    ‘stats_views’ => 0
    ));
    }
    ?>

    And this code for month views :
    <?php
    if ( function_exists(‘wpp_get_mostpopular’) ) {
    wpp_get_mostpopular(array(
    ‘limit’ => 5,
    ‘range’ => ‘last30days’,
    ‘order_by’ => ‘views’,
    ‘stats_views’ => 0
    ));
    }
    ?>

    • This topic was modified 4 years ago by Rami.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @rami4625,

    That’s not really possible without some custom coding work: you’d need to retrieve the IDs of the most popular posts from the last 7 days (you can use the \WordPressPopularPosts\Query class for this for example) and then pass these IDs to the second function using the pid parameter.

    Thread Starter Rami

    (@rami4625)

    Hi @hcabrera ,

    Thanks for respond,
    Can you give me specific example to do that?
    That’s will help me more.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Thread Starter Rami

    (@rami4625)

    That’s work but I should use (implode) to make it work,

    The code now look like this:

    <?php
    if ( function_exists(‘wpp_get_mostpopular’) ) {

    // Get Popular Posts IDs
    function get_popular_posts_ids($range, $limit)
    {
    $post_IDs = array();
    $query = new \WordPressPopularPosts\Query([
    ‘range’ => $range,
    ‘limit’ => $limit
    ]);
    $popular_posts = $query->get_posts();
    // Popular posts found, get their IDs
    if ( is_array($popular_posts) && ! empty($popular_posts) ) {
    foreach($popular_posts as $popular_post) {
    $post_IDs[] = $popular_post->id;
    }
    }
    return $post_IDs;
    }

    // Gets the 5 most viewed posts from the last 30 days
    $post_ids_array = get_popular_posts_ids(‘last30days’, 5);

    // Gets Each Item In $post_ids_array
    $post_ids_items = implode(“,”, $post_ids_array);

    wpp_get_mostpopular(array(
    ‘limit’ => 5,
    ‘range’ => ‘last7days’,
    ‘order_by’ => ‘views’,
    ‘stats_views’ => 0,
    ‘pid’ => $post_ids_items
    ));

    }
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude Posts’ is closed to new replies.