• Resolved Nimesh

    (@nimeshrathod1gmailcom)


    Hello Author,

    I’ve latest wordpress, CPT plugin

    I need below slug change for my post :
    BASE URL/taxonomy name/post type name/post title
    ex :
    BASE URL/company/news/post type
    BASE URL/private/news/post type

    So for that :
    Rewrite = True
    Custom Rewrite Slug = /%taxonomy_name_for_news%/news

    In function.php

    
    function wpa_course_post_link( $post_link, $id = 0 )
    {
        $post = get_post($id);  
        if ( is_object( $post ) && (get_post_type($id) == "news" || get_post_type($id) == "kampanjer" )){
        
            $terms = wp_get_object_terms( $post->ID, 'taxonomy_name_for_news' );
            if( $terms ){
                return str_replace( '%taxonomy_name_for_news%' , $terms[0]->slug , $post_link );
            }
        }
        return $post_link;  
    }
    add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );
    

    It work for this CPT
    ———-
    Same above setting I was done for second CPT.
    and than check frontend this post, it will redirect on “page not found” page

    Also all other pages, are also redirect on 404

    Do you have any idea, like why other post + pages say 404?
    Also just FYI : I’ve same name of 2 page, what taxonomy name have, like :
    For ex :
    page name : company, private

    • This topic was modified 3 years, 4 months ago by Nimesh.
    • This topic was modified 3 years, 4 months ago by Nimesh.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m not great with permalink customization as it’s a pretty complex topic to work with.

    I suspect the 404 errors are because WordPress is trying to query things differently than what you’re thinking and intending to query for. I would be interested to see the resulting SQL request for these spots and see what it’s interpreted being requested. Part of the thing with permalink rewrites is that each component is important in telling WordPress what to try and grab.

    As a quick example of what I mean, take this structure:

    /tax-term-slug/post-type-slug/post-title

    and this example result:

    /company/news/new-president-elected

    WordPress needs to be able to know that it’s not: “ok, is company the post type? and news…is that a parent post? with a child post of ‘new-president-elected’ ?”

    vs “okay, ‘news’ is the post type slug, and ‘new-president-elected’ is the post to display. And, oh yes, we need to output the taxonomy term of ‘company’ at the start of it, but it shouldn’t dictate what gets queried at all”

    It also sounds like you have PAGES named “company” and “private” along side those being terms in this taxonomy, which could be making requests to /company/news/new-president-elected come off as possibly grandchild pages, when they’re not.

    Thread Starter Nimesh

    (@nimeshrathod1gmailcom)

    Hello @tw2113

    thank you for your quick reply.

    I understand what you trying to explain.

    But this is what I actual face problem

    Well, lets wait if any body know more with this issue and can help me

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    For what it’s worth, and admittedly a little pedantic, it’s not so much an issue with CPTUI itself, but making use of and customizing details around the content types registered with it.

    I am definitely willing to leave the thread open though in case someone else sees it who has some experience, and if any ideas come to mind for me, I’ll pass them along.

    That said, the part above about the SQL request being made would probably still be the best first step here, at least with what we have thus far. This would be part of the WP_Query object if I’m not mistaken.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘After change URL, other page say not found’ is closed to new replies.