• Resolved lscura

    (@lscura)


    Hello,

    I was just wondering if is it possible to pull the most popular articles each month? Like have most popular articles in February, then March, etc

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter lscura

    (@lscura)

    Update:
    I’ve added “date parameters” of WP_Query to only show posts from the past month. Will it work?
    $args = array(
    ‘post__in’ => $topposts,
    ‘orderby’ => ‘post_date’,
    ‘numberposts’ => $limit,
    ‘posts_per_page’ => $limit,
    ‘ignore_sticky_posts’ => $ignore_sticky,
    ‘date_query’ => array(
    array(
    ‘year’ => date( ‘Y’ ),
    ‘month’ => date( ‘M’ ),
    ),
    ),
    );

    • This reply was modified 3 years, 7 months ago by lscura.
    Thread Starter lscura

    (@lscura)

    This code seems to finally work:

    $args = array(
                'post__in' => $topposts,
                'orderby' => 'post_date',
                'numberposts' => $limit,
                'posts_per_page' => $limit,
                'ignore_sticky_posts' => $ignore_sticky,
                'date_query' => array(
                    array(
                        'after' => '30 days ago',
                        'inclusive' => 'true'
                    ),
                )
            );
    • This reply was modified 3 years, 7 months ago by lscura.
    Plugin Author Ajay

    (@ajay)

    Thanks – not that the above will pull out based on the dates the post is published . I’m working on a new version which will allow you to pass a from_date and to_date which pulls the popular posts for a period when it was tracked.

    Thread Starter lscura

    (@lscura)

    Thanks for answering!
    That is weird. I tested with some articles within the last 30 days and even though I published some articles they were not showing up until I visited them. And then on the frontend, there was showing up only the articles with more visits. That is why I thought it worked!

    • This reply was modified 3 years, 7 months ago by lscura.
    Plugin Author Ajay

    (@ajay)

    I think it depends on the frequency your newer posts are hit – which could be more frequent than older ones.

    I’m about a few weeks away from Top 10 v3.0.0 and you’ll be then able to skip the WP_Query and use Top_Ten_Query and use to_date and from_date to set the date limits.

    I’ll have a beta of this out in the repository likely tonight.

    • This reply was modified 3 years, 7 months ago by Ajay.
    Plugin Author Ajay

    (@ajay)

    I’ve put out a beta here: https://github.com/WebberZone/top-10/releases/tag/v3.0.0-beta1

    This allows you to add the from_date and to_date as additional parameters as additional parameters to Top_Ten_Query. It works same as WP_Query – but use Top_Ten_Query instead. You won’t need the post__in as above. Add you add add the two args with the from and to which will pull out the dates related to when the plugin tracks hits and not the published date of the post.

    Thread Starter lscura

    (@lscura)

    Thank you!
    This looks promising! I will definitely try it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Pull the most popular article each month’ is closed to new replies.