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
280 stars 83 forks source link

Add exclude current post functionality #199

Closed brunocasanova closed 5 years ago

brunocasanova commented 5 years ago

It would be great if that was a feature that we could hide the current post from the results. Ex. When we are seeing some post and give us the possibility to choose if that specific post doesn´t show on the wpp related posts on the same page.

I needed this functionality and i couldn't find any workaround for this in the forums and in the web and had notice that was more people asking for this functionality.

I saw people hiding the current posts via css with this workaround .wpp-list .current{display:none !important;} but in reality this was only hiding the post and reducing the results in one.

I wanted that the result was excluded in the query, not affecting the number of the results and only in some of the instances so that in this way i could have an option to choose in which instance i excluded the current post from the results.

So i added a field called exclude_current that have the option to exclude from the query and injecting the get_the_ID() before the pid filtering.

Im not really sure if im using the best practices that you are using at the moment but is working as expected in my website and it was running nice in tests.

PS. I made a fix commit after this one and if is needed i can make the PR in a separate branch.

brunocasanova commented 5 years ago

I made a fix commit and if is needed i can make a separate branch.