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

    (@hcabrera)

    Hi Robert, sorry for the late reply.

    It seems the gist is missing or that the URL is no longer valid. Anyways, you might be interested in checking my Github repo, I’ve added a hook (wpp_custom_html) which you can use to get the raw query result in order to build your own HTML list.

    Where is the wpp_custom_html and how can we use it. I have same sort of problem and need the result in an array

    Plugin Author Hector Cabrera

    (@hcabrera)

    Be aware that this hook I mentioned above is not available on the current official release (version 2.3.7 at the time of writing this). You can only use it on the development version on Github.

    This is how you would hook to the raw query result:

    /*
     * @param string $html: original HTML output.
     * @param array $popular_posts_array : array of objects containing
     * the popular posts information.
     */
    function my_custom_html( $html, $popular_posts_array ){
    	// Loop $popular_posts_array and build your custom HTML,
    	// and return it when you're done.
    }
    add_filter( 'wpp_custom_html', 'my_custom_html', 10, 2 );

    Add that piece of code to your theme’s functions.php file.

    Keep in mind that the code on Github is still highly experimental and it may be changed / removed without prior notice.

    Hi,

    I’d very interested to be able to call a function in order to get an array of popular post. It would be similar to class private get_popular_posts().

    I’m trying to use this data with a 3rd party widget.

    Thanks in advance.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Hi pakus,

    This is how I would do it:

    1. Hook into the plugin using the wpp_custom_html filter as explained above to retrieve the array of posts.
    2. Then, use wpp_get_mostpopular() to echo the list.

    All this, of course, once version 3.0 is officially available.

    <?php 
    
    if (function_exists('wpp_get_mostpopular')) {
    
    	add_filter( 'wpp_html', 'wpp_get_array', 10, 2);
    
    	function wpp_get_array($content, $posts_data) {
    
    		return $posts_data;
    
    	}
    
    	$popular_posts_object = new WordPressPopularPosts;
    
    	$instance = array(
    		'range' => 'monthly',
    	);
    
    	$popular_posts = $popular_posts_object->get_popular_posts( $instance );
    
    	var_dump($popular_posts);
    
    }

    This code gets an array of popular posts to $popular_posts variable.
    Works with Popular Posts plugin since 2.3.6 version.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Output as array of post objects.’ is closed to new replies.