Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @suffianshakoor

    Unfortunately, there is no out-of-box solution available. You can however try to use the below code snippet and control how the new custom permalinks are generated.

    After you implement it, whenever a new custom permalink is generated for a new item, the default permalink for it will be forced to be unique:

    function pm_unique_permalinks( $default_uri, $native_slug, $element, $post_name, $native_uri ) {
    	global $permalink_manager_uris;
    
    	// Ignore native permalinks
    	if ( $native_uri ) {
    		return $default_uri;
    	}
    
    	// Store all the custom permalinks in a separate variable
    	$uris = $permalink_manager_uris;
    
    	// Exclude this element
    	if ( ! empty( $element->ID ) && ! empty( $uris[ $element->ID ] ) ) {
    		unset( $uris[ $element->ID ] );
    	} else if ( ! empty( $element->term_id ) && ! empty( $uris[ $element->term_id ] ) ) {
    		unset( $uris["tax-{$element->term_id}"] );
    	}
    
    	do {
    		$duplicates_ids       = array_keys( $uris, $default_uri );
    		$duplicates_ids_count = count( $duplicates_ids );
    
    		if ( ! empty( $duplicates_ids_count ) ) {
    			preg_match( '/(.+?)(?:-([\d]+))?(\.[^\.]+$|$)/', $default_uri, $parts );
    			$index = ( ! empty( $parts[2] ) ) ? $parts[2] + 1 : 2;
    
    			$default_uri = preg_replace( '/(.+?)(?:-([\d]+))?(\.[^\.]+$|$)/', '$1-' . $index . '$3', $default_uri );
    		}
    	} while ( $duplicates_ids_count > 0 );
    
    	return $default_uri;
    }
    add_filter('permalink_manager_filter_default_post_uri', 'pm_unique_permalinks', 999, 5);
    Thread Starter suffianshakoor

    (@suffianshakoor)

    @mbis Thank you for sharing the code snippet. I’ve implemented it as suggested, but unfortunately, it doesn’t seem to be addressing the issue of preventing duplicate URLs. The default permalink is being forced to be unique as expected. But after the creation of new post We can still change the URLs from Permalink Manager Lite and make the URLs as same as already exists.

    I wanted to reach out to see if there might be additional steps or modifications needed to achieve the desired outcome. If there are any alternative approaches or if there have been updates since the provided solution, I would greatly appreciate any further guidance you can provide.

    Thank you

    Thread Starter suffianshakoor

    (@suffianshakoor)

    I am asking these changes because i have created two jobs with the same URLs with the help of permalinks manager lite. I have set one job as private and the other as published. However, the private job’s URL is displaying instead of the published one. Even when you open the page in a private window, it shows a 404 error. It might be possible that the system does not grant access to either of them or only allows access to the private one.
    URL : https://www.placedrecruitment.com.au/job/group-chef-director-of-culinary-to-220-s-large-complex-business/
    Screenshot : https://www.awesomescreenshot.com/image/45151917?key=e0b857a6843e3409c10c799ae5b8f729

    Plugin Author Maciej Bis

    (@mbis)

    Hi @suffianshakoor,

    According to the debug data, it seems that Permalink Manager ignores that “private” job:

    https://www.placedrecruitment.com.au/job/group-chef-director-of-culinary-to-220-s-large-complex-business/?debug_url

    If this is the case, the plugin should load the second published job as long as it uses the same custom permalink (job/group-chef-director-of-culinary-to-220-s-large-complex-business).

    Could you check if the custom permalink is saved for the second job in the “Debug” section (the first textarea field):

    Thread Starter suffianshakoor

    (@suffianshakoor)

    @mbis As you can see the URL is there two times :
    job/group-chef-director-of-culinary-to-220-s-large-complex-business
    https://www.awesomescreenshot.com/image/45156920?key=9913b68c32a69f10c6b9f94b6c918950

    Plugin Author Maciej Bis

    (@mbis)

    Hi @suffianshakoor,

    Could you try to use this code snippet instead?

    function pm_ignore_private_posts( $excluded, $element_object, $old_query, $pm_query ) {
    	if ( ! empty( $element_object->post_status ) && $element_object->post_status == 'private' ) {
    		$excluded = $element_object->ID;
    	}
    
    	return $excluded;
    }
    add_filter( 'permalink_manager_excluded_element_id', 'pm_ignore_private_posts', 50, 4 );
    Thread Starter suffianshakoor

    (@suffianshakoor)

    @mbis The issue we previously reported has been successfully resolved after implementing the provided code.
    I appreciate your prompt attention to this matter and the collaborative effort in resolving the issue.

    Thank you for your assistance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.