• Resolved aloteri

    (@aloteri)


    Hi,

    first of all, thanks for the amazing script.

    As deafult the listing page uses the overall permalink setup, so if I use “/blog/%postname%/” for the blog section also the listing page will use the slug “blog”.

    My question is, how can I not use the “blog” slug and use the directory slug instead?

    I read here on the support forum a similar request with the Post ID, but I would like to use the post_name function. I tried with this code, the first part works well, but something is wrong on the rewrite rule (second part).

    function acadp_post_type_link( $post_link, $post = 0 ) {
        if( $post->post_type === 'acadp_listings' ) {
    	$permalink_settings = get_option( 'acadp_permalink_settings' );
            return home_url( $permalink_settings['listing'].'/' . $post->post_name . '/' );
        } else {
            return $post_link;
        }
    }
    add_filter( 'post_type_link', 'acadp_post_type_link', 1, 3 );
    
    function acadp_rewrites_init(){
        $permalink_settings = get_option( 'acadp_permalink_settings' );
        add_rewrite_rule( $permalink_settings['listing'].'/([0-9]+?$', 'index.php?post_type=acadp_listings&p=$matches[1]', 'top' );
    }
    add_action( 'init', 'acadp_rewrites_init' );
    

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author pluginsware

    (@pluginsware)

    Hi,

    Kindly replace your existing code with the following,

    function acadp_remove_blog_prefix( $args, $post_type ) {
    if ( $post_type == ‘acadp_listings’ ) {
    $args[‘rewrite’][‘with_front’] = false;
    }

    return $args;
    }

    add_filter( ‘register_post_type_args’, ‘acadp_remove_blog_prefix’, 10, 2 );

    Hope this solved your issue!

    Thanks

    Thread Starter aloteri

    (@aloteri)

    Super super thank you.
    It perfectly works !

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Single Listing Permalink’ is closed to new replies.