Site logo

Archived topic

How to hide posts from homepage that are on WP Show Posts Pro

6 replies · Started by Elio Martinez on June 14, 2020

Viewing posts 1–7 of 7

Hi,

Currently my homepage is:

1. One list made with WP Show Post Pro showing 4 posts inside an Element in the Header Hook.
2. My last posts.

Is there a way to not show on my last posts the posts that are on the WP Show Post Pro?

Thanks.

Hi David,

If I add that function to my child functions I get a weird homepage: the 4 posts shown in WP Show Posts Pro (via tag or category because they are not the 4 last posts, they are the 4 last post with a specific tag or category) get shown in the lasts posts too and if someone clicks on "load more" posts on home page get the same posts every time he or she clicks on "load more".

Ok, I got resolved this with this function:

add_filter('pre_get_posts', 'excludeCat');
function excludeCat($query) {
      if ( $query->is_home ) {
            $query->set('cat', '-3936');
      }
      return $query;
}

If I want to change this function to exclude a tag it must be like this?:

add_filter('pre_get_posts', 'excludeTag');
function excludeCat($query) {
      if ( $query->is_home ) {
            $query->set('tag', 'XXX');
      }
      return $query;
}

aah ok - yes that query looks correct for Tags.

Great. Thanks!

Glad to be of help

This archived topic is closed to new replies.