Support » Plugin: WordPress Infinite Scroll - Ajax Load More » Sort by post with most views in 48 hrs

  • Hi, I would like it to sort by and show the posts with most views in the past 48 hrs in a specific category/tag. How can I achieve this? I am a newbie, please make it simple.

    Thank you,

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author dcooney

    (@dcooney)

    Hi @dulexc,
    Are you tracking this data in your theme currently?

    Thread Starter Mr509

    (@dulexc)

    Yes, I track post views in my theme.

    Plugin Author dcooney

    (@dcooney)

    Removed this post… continued below….

    • This reply was modified 4 years, 5 months ago by dcooney.
    Plugin Author dcooney

    (@dcooney)

    Then you can just figure out the custom field name that tracks posts and use it like so.

    echo do_shortcode('[ajax_load_more id="popular" post_type="post" meta_key="your_key_name" orderby="meta_value_num"]');

    Replace your_key_name with your custom field name for tracking views.

    For the past 48hrs part. This is tricky with Ajax Load More. Your best bet is to use the alm_query_args filter and use a date_query.

    function my_popular_posts($args){
     
      $args['date_query'] = array(
          array(
             'after' => '2 days ago'
          )
      );
      return $args;
     
    }
    add_filter( 'alm_query_args_popular', 'my_popular_posts' );

    Hope this works for you.
    Cheers,

    Could be very nice with some additional WooCommerce-examples for this. I think it’s pretty hard for many, to understand how you can customize the query (sorting).

    Thread Starter Mr509

    (@dulexc)

    I got it to show the most popular posts by views.

    I still need your help to sort them by the most popular posts in the past 48 hrs.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Sort by post with most views in 48 hrs’ is closed to new replies.