• Resolved LuxDelux

    (@luxdelux)


    Hello, first of thanks for this great plugin πŸ™‚

    I’m trying to make my custom popular posts list by getting the array from getMostVisitedPostIDs. Here’s what I have so far:

    <?php
    global $count_per_day;
    $valute = $count_per_day-> getMostVisitedPostIDs(7,1,true,true);
    $pquery = new WP_Query( array( 'post_type' => 'post', 'post__in' => $valute,'orderby' => 'count' ) );
    
    if ( $pquery->have_posts() ) {
            echo '<ul>';
    	while ( $pquery->have_posts() ) {
    		$pquery->the_post();
    		echo '<li>' . the_post_thumbnail('thumb-medium') . '</li>';
    	}
            echo '</ul>';
    } else {
    	// no posts found
    }
    
    ?>

    I get the output but the listed items follow no order, also, changing the value of $limit to example 1 still displays all of my posts (I have only 3 for testing). Any tips or ideas? Cheers

    https://wordpress.org/plugins/count-per-day/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author tom-braider

    (@tom-braider)

    Your array $valute contains the IDs, titles, and counts of the records. not only the IDs. So i think it will ignored in the query.
    Use getMostVisitedPostIDs(7,1,true,false) to get an ID list and explode them to an array.

    Thread Starter LuxDelux

    (@luxdelux)

    Awesome, I’m fairly new to php so didn’t know about explode (as I initially tried to first push the ID list into an array).

    Here’s the final output, works as expected, query monitor shows no errors πŸ™‚

    <?php
    global $count_per_day;
    $valute = explode(',',$count_per_day-> getMostVisitedPostIDs(7,5,false,false));
    $pquery = new WP_Query( array( 'post_type' => 'post', 'post__in' => $valute ) );
    
    if ( $pquery->have_posts() ) {
            echo '<ul>';
    	while ( $pquery->have_posts() ) {
    		$pquery->the_post();
    		echo '<li>' . the_post_thumbnail('thumb-medium') . '</li>';
    	}
            echo '</ul>';
    } else {
    	// no posts found
    }
    
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘getMostVisitedPostIDs not working?’ is closed to new replies.