Site logo

Archived topic

Checking for post restriction in custom post type archive

5 replies · Started by Anastasiya on April 29, 2022

Viewing posts 1–6 of 6

Hi,

I have set up Content Element (block) to display for a custom post type on archive pages. I am using Restrict Content Pro for content restriction.
For some reason the custom posts are not being filtered on my custom post type by restriction. The restriction filter works great on a regular post page (blog.) I understand that this can be an issues with RCPRo handling the post filtering.

My question, can I use a hook on my custom post type archive page that would hide specific posts from the loop?
The conditional filter that is available is the following:

if( rcp_user_can_access( get_current_user_id(), get_the_ID() ) ) {
	// user can access
} else {
	// user cannot access
}

Can I use this condition with generate_before_content hook?

Hi there,

I'm not sure about this as its not a WP or GP function.

You may have a try though.

I probably didn't explain my question correctly.

Os it possible to execute a conditional check before an element is displayed on a custom archive page? I tried using hook generate_before_content but it doesn't fire with a content element that I set up in GP Elements.

I tried using hook generate_before_content but it doesn’t fire with a content element that I set up in GP

No, this will not work. Those hooks only works in the default GP template as there's no such hook created in your content template.

Hope I made it clear.

Got it, thanks,

Is there any way to add conditions or extra checks to my custom post type loop? Or maybe a better way to set this up?

If you are trying to apply a general condition like hide posts from specific categories, then you can try something like this:
https://generatepress.com/forums/topic/adding-custom-field-to-query-loop-for-post-summaries/#post-2203811

You can use is_post_type_archive conditional tag to target custom post type archive:
https://developer.wordpress.org/reference/functions/is_post_type_archive/

But if your condition is related to the plugin's function, I would recommend reaching out to the plugin support as it might not work with custom post loops.

This archived topic is closed to new replies.