Skip Navigation

[Resolved] Remove the permalinks from a CPT

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.

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)

This topic contains 6 replies, has 3 voices.

Last updated by Minesh 8 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2687816

Tell us what you are trying to do?
Hi,

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?

What I understand from the WordPress documentation is that I should set the "public" property as false, though I can't see that option in Toolset's "Edit Post Type" form. https://developer.wordpress.org/reference/functions/register_post_type/

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.

What is the link to your site?
hidden link

#2687858

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I think you can benefit from a quirk in Views with respect to Access.

You can use Access to limit the visibility of posts by post type, see https://toolset.com/course-lesson/setting-access-control/, which you can do to your review post type.

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.

#2688496

Hi Nigel,

Thanks for the tip. It is useful though what if I don't want any permalinks to be generated?

#2688540

Minesh
Supporter

Languages: English (English )

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

Premalinks are required to access the post.

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.

#2689228

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.

#2689468

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Minesh is off today, let me step in.

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.)

#2689720

Minesh
Supporter

Languages: English (English )

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

Can you please try to follow the solution shared by Nigel with the following reply and try to resolve your issue:
- https://toolset.com/forums/topic/remove-the-permalinks-from-a-cpt/#post-2689468