cabrerahector / wordpress-popular-posts

WordPress Popular Posts - A highly customizable WordPress widget that displays your most popular posts.
https://wordpress.org/plugins/wordpress-popular-posts/
GNU General Public License v2.0
279 stars 83 forks source link

Allow extra Where clause #307

Closed MaraScott closed 3 years ago

MaraScott commented 3 years ago

Is your feature request related to a problem? Please describe. On our website we have post which have a publication status as published or private with a visibility status as public or private. We can t filter out content that have a visibility status as private.

Describe the solution you'd like We like an extra parameter that would allow us to add extra where clause like AND (SELECT pm.meta_value FROM wp_postmeta as pm WHERE pm.post_id = p.ID AND pm.meta_key = 'visibility') <> 'private' or extra parameter that specificaly target wp_postmeta key/value pair

Describe alternatives you've considered so far we put in file wp-content/plugins/wordpress-popular-posts/src/Query.php l.455 the following $where .= " AND (SELECT pm.meta_value FROM wp_postmeta as pm WHERE pm.post_id = p.ID AND pm.meta_key = 'visibility') <> 'private'";

cabrerahector commented 3 years ago

Hi @davask,

Well, if you take a closer look at the Query.php file you'll notice that it includes some undocumented filter hooks that you can use to alter the query without having to edit the code :P Please check lines 460 to 466 for more details.

MaraScott commented 3 years ago

Hi @cabrerahector,

I was such in hurry to find a quick fix I missed that point. Thanks for the heads up. The filter is now in place.

Best regards,

david