• Resolved Enpeiks

    (@enpeiks)


    Hi everyone!

    I must display Most Popular 3 posts on my page (front-page). Now I just using
    <?php wp_statistics_get_top_pages(); ?> but this code display 10 posts- not 3.

    Is possible to configure this PHP code? E.x. posts from diffrent category, displaying most popular posts 3, 6 or 10 etc. etc ?

    Thanks!
    Sry for my bad English 🙁

    https://wordpress.org/plugins/wp-statistics/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Greg Ross

    (@gregross)

    wp_statistics_get_top_pages() returns an array with the results in it so you could just loop through the first three entries instead of all of them.

    Thread Starter Enpeiks

    (@enpeiks)

    Thanks for response!
    Ok I make my WP_QUERY Loop but it’s possible sort displayed posts by visits ?

    My loop:

    <?php
                        $variable = wp_statistics_get_top_pages();
                        $poststat = array();
                            foreach ($variable[1] as $key => $value) {
                                $poststat[] = $value[2];
                        }
                    ?>
    
                    <?php
                        $getPopularOffers = new WP_Query( array( 'post_type' => 'offer', 'post__in' => $poststat, 'orderby' => 'rand' ) );
                    ?>
    Plugin Contributor Greg Ross

    (@gregross)

    In general yes, though obviously if you only want the top three you’d replace the foreach() with a for( $i = 0; $i < 3; $i++ ) loop.

    Plugin Contributor Greg Ross

    (@gregross)

    Oh, and since this is an expensive database query to run, you might want to cache the results so it only runs once in a while using set_transient.

    Thread Starter Enpeiks

    (@enpeiks)

    Thanks but maybe you can help me write this code ? I have low skill in PHP 🙁

    Plugin Contributor Greg Ross

    (@gregross)

    Sorry, no, that’s beyond the level of support we offer.

    Thread Starter Enpeiks

    (@enpeiks)

    Ok thanks!
    I will try- thanks for all!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display most popular posts’ is closed to new replies.