• Resolved x1code

    (@secretja)


    Hi,

    After update of plugin and WordPress, on staging, I have a problem with removing post type slug. Slug is “landing”.

    CPT UI settings for custom post type:

    Rewrite: True
    Custom Rewrite Slug: empty
    With Front: False.

    Functions:

    function na_remove_slug( $post_link, $post, $leavename ) {
    
        if ( 'landing' != $post->post_type || 'publish' != $post->post_status ) {
            return $post_link;
        }
    
        $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
    
        return $post_link;
    }
    add_filter( 'post_type_link', 'na_remove_slug', 10, 3 );
    
    function na_parse_request( $query ) {
    
        if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
            return;
        }
    
        if ( ! empty( $query->query['name'] ) ) {
            $query->set( 'post_type', array( 'post', 'landing', 'page' ) );
        }
    }
    add_action( 'pre_get_posts', 'na_parse_request' );

    All works on production but on staging I get 404. Can subdomain.domain.com affect this? I don’t have any other good ide why this don’t work.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Have you flushed your permalink rules recently? That can be done via visiting the permalinks settings page and just clicking save without touching anything.

    I don’t think the domain matters, or in this case subdomain.

    We also presently recommend a well-tested permalinks plugin like https://www.ads-software.com/plugins/permalink-manager/ for this type of customization. Worth checking out and trying, and would remove the need for the extra code above.

    Hi Michael, I have a similar issue (so I won’t open another post).

    I created a new content type (called “Copywriting”). I need the URLs of these content types to show the Post_ID, like I do for articles and pages.

    For example, an article is example.com/?p=123

    CTP UI does something similar, since it creates example.com/?copywriting=slug . However, I need to remove the slug part and make it so that the url looks like this: example.com/?copywriting=456

    Is it possible to do directly with your plugin? I searched all around with the options, but I can’t find it. I also tried with Permalink Manager, but I can’t find a way to show the URL with ? and = symbols.

    Thank you ??

    • This reply was modified 1 year, 11 months ago by hornedcrosis.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi @hornedcrosis, CPTUI itself doesn’t do anything special with rewrites, outside of allow for specifying what the slugs for the content types could be. As a very quick example, changing “copywriting” to “copyediting” for the permalinks.

    From what I see with your request the permalink would essentially read as “post_type=post_id” which would be a bit interesting to attempt to implement. the “p=post_id” already gets mapped internally when WordPress parses out the request. So you’d need to somehow set rewrites and mapping to somehow have “copywriting” get parsed out as “this will be the post ID to fetch”. I don’t have answers for how to achieve that admittedly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove post type slug’ is closed to new replies.