Skip Navigation

[Resolved] remove CPT from /category/category-slug/ page

This support ticket is created 8 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 8 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#372762

I have a similar issue to this post:

https://toolset.com/forums/topic/how-to-exclude-a-specific-custom-post-type-from-a-taxonomy-archive-loop/

I have a CPT (articles) sharing the default WP Categories - so have used this code to only return posts on the /category/category-slug/ templates:

add_action( 'pre_get_posts', 'exclude_cpt' );
function exclude_cpt( $query ) {
    if ( $query->is_category() ) {
        $query->set('post_type','post');
    }
    return $query;
}

But this returns both my posts and my CPT?

If I change to this:

$query->set('post_type','article');

Then it only returns CPT articles??

How do I change this to only show my posts?

Confused 🙁

#372857

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I will try to help you as fast and effective as possible, so you can go on with your project and to remove your confusion. I would like to review your setup.

1)
Could you please share problem URL and where you have added above code?

2)
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#373416

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share your problem URL?

#373439

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked but I can see that the query we set at run time is not set and its displaying post from both post type.

*** Please make a FULL BACKUP of your database and website.***
Could you please try to resolve your issue by deactivating all third-party plugins as well as with the default theme to check for any possible conflicts with any of the plugins or themes?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.