I have a CPT that I display on the frontend but the CPT doesn't have its own content template. These CPTs are created via a post form by visitors. I have to set the "publicly_queryable" as true because I cannot create form for it otherwise. How can I make sure no permalink is created for these CPTs?
Example:
I have companies (CPT 1) and also reviews for companies (CPT 2). I display the reviews only on the company page, so I don't want reviews (CPT 2) to have their own permalinks.
The quirk is that Views doesn't respect such Access settings, and so you can still show such posts in the output of your View, even though users will not be able to visit URLs of the posts directly.
I would like to know how reviews are added - is it added from frontend? Is it using Toolset forms?
- If you are using Toolset form you can use Toolset form hooks such as "cred_save_data" or "cred_submit_complete" using which you can override the permalink as per your requirement.
The reviews are added from the frontend via a Toolset Form.
They are not displayed by themselves, but they are only displayed via a view in another content template. If possible, I don't want them to have their own permalinks, so I'm not looking to override the permalink created.
If this is not possible that's ok, I can think of alternatives that might suit me. But my understanding from the WordPress docs is that this is possible via the "public" property, which I don't see a way to set via Toolset.
I'm not sure if setting the 'public' property to false for the post type will do what you want, but you can do so by overriding the arguments used to register the post type, using the WordPress filter register_post_type_args (see
So for a post type with slug of "thing" you could do that like so:
/**
* Override register_post_type 'public' argument for specified post type
*/
add_filter( 'register_post_type_args', 'ts_filter_post_type_args', PHP_INT_MAX - 1, 2 );
function ts_filter_post_type_args( $args, $type ){
if ( $type == 'thing' ) {
$args['public'] = 'false';
}
return $args;
}
(Note you need to add the code to the functions.php file of your child theme, the Toolset snippets feature runs too late.)