Sort Popular Posts by Views for the Last Week

Use strtotime to compare dates. $start = strtotime(‘yesterday’); $end = strtotime( ‘+1 week’,$start); $args = array( ‘posts_per_page’ => 5, ‘ignore_sticky_posts’ => 1, ‘meta_key’ => ‘sw_post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘date_query’ => array( ‘after’ => $end, ‘before’ => $start, ), ); $popularpost = new WP_Query( $args ); if ( $popularpost->have_posts() ) { while ( … Read more

Popular posts by view with Jetpack

There is a Jetpack widget called Top Posts and Pages (Jetpack) If you check out the [source code][2] for this widget, you can see that it’s using the function stats_get_csv() to retrieve the stats: $post_view_posts = stats_get_csv( ‘postviews’, array( ‘days’ => 2, ‘limit’ => 10 ) ); If you want to generate your custom most … Read more

Show popular post in another php website via WP REST JSON API

I will give you a small answer to your update, doing this with the WP API. The API have the possibilities to use the WP_Query like also in core, but about the get parameters in the url. A URL to pull content from Post Status would look like this: http://example.com/wp-json/posts To pull content with WP_Query … Read more