Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is a way to get to the raw popular post data on an instance basis. #122

Closed
pixeline opened this issue Dec 13, 2016 · 2 comments
Closed

Comments

@pixeline
Copy link

pixeline commented Dec 13, 2016

Hello @cabrerahector and thank you very much for the work you've put into the plugin. This is my modest contribution, perhaps it will help other folks in similar situation.

In this project I'm busy on, we need the widget but also a place in the template where the output is hardcoded, with specific parameters and layout. I wanted to have access on the raw selection of posts returned by the plugin on an instance basis. (Using the filter as suggested in the documentation modifies the output for all instances).

I tweaked Phil Smart's example class to use the filter you provided. Here is the modified class, which returns an array of WP objects that I can then manipulate as i see fit. Handy.

In the template:

$popular_blog_posts = new Popular_Posts_Data(
      array(
			'range'     => 'monthly',
			'freshness' => 1,
			'orderby'   => 'views',
			'limit'     => 3,
			'post_type' => 'post,reportage'
      ) );

print_r( $popular_blog_posts->get_posts() );

Sample output:

Array
(
    [0] => stdClass Object
        (
            [id] => 29
            [title] => Sophie Rogers : les hommes de sa vie
            [date] => 2016-12-06 10:44:10
            [uid] => 4
            [pageviews] => 148
        )

    [1] => stdClass Object
        (
            [id] => 613
            [title] => RANIA OFFRE À JULIETTE UN CADEAU POUR SA FILLE
            [date] => 2016-12-12 11:46:18
            [uid] => 3
            [pageviews] => 50
        )

    [2] => stdClass Object
        (
            [id] => 12
            [title] => "Je veux m’occuper de moi, maintenant"
            [date] => 2016-11-30 19:24:05
            [uid] => 3
            [pageviews] => 39
        )
)
@cabrerahector
Copy link
Owner

Hi there!

I'm sure other users will take advantage of your work, so thanks for sharing! You might want to leave a comment on Phil's blog post to let him and his visitors know what you built.

Actually, I've been working on a native WPP class that does exactly this. You might want to check it out since it'll be the "stock" way of doing it in the (near) future

@pixeline
Copy link
Author

pixeline commented Dec 14, 2016

Actually, I've been working on a native WPP class that does exactly this. You might want to check it out since it'll be the "stock" way of doing it in the (near) future

Ah, I was secretly hoping you'd say that :) It's definitely useful because, personally I am used to the WP_Query API and that would not require me to learn another one if I need to build a custom loop. I'll have a closer look in the coming days. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants