• One permalink can be set more than once, which causes errors.
    My permalinks are set to posttitle.
    New wordpress install. First I have created the page with title test. Url was /test.
    Then an post with ttilte test. Permalink manager set the url also to /test. If i try now to access /test it shows me the post.

Viewing 8 replies - 16 through 23 (of 23 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Yes, I am preparing one more solution.

    Thread Starter aceone999

    (@aceone999)

    Well, but both snippset do not to work correctly with my form plugin.

    Plugin Author Maciej Bis

    (@mbis)

    What form plugin do you use?

    Plugin Author Maciej Bis

    (@mbis)

    The new snippet is ready. The hook is triggered after:

    • new post is added & custom permalink generated
    • existing post is updated via WordPress admin dashboard
    function pm_force_unique_permalinks($post_id, $new_uri, $old_uri) {
    	global $permalink_manager_uris;
    
    	while(empty($new_unique_permalink)) {
    		$duplicates = array_keys($permalink_manager_uris, $new_uri);
    
    		if(is_array($duplicates)) {
    			$duplicated_ids = array_flip($duplicates);
    
    			// Ignore this particular post
    			if(isset($duplicated_ids[$post_id])) {
    				unset($duplicated_ids[$post_id]);
    			}
    
    			// Count duplicates
    			$duplicates_count = count($duplicated_ids) + 1;
    
    			// Add numeral prefix to the URL
    			if($duplicates_count > 1) {
    				preg_match('/(.*)-([\d]{1,3})$/', $new_uri, $out);
    				
    				if(!empty($out[2])) {
    					$new_uri = sprintf('%s-%d', $out[1], (int) $out[2] + 1);
    				} else {
    					$new_uri = preg_replace('/(.+?)(\.[^\.]+$|$)/', '$1-' . $duplicates_count . '$2', $new_uri);
    				}
    			} else {
    				$new_unique_permalink = $new_uri;
    			}
    		}
    	}
    
    	$permalink_manager_uris[$post_id] = $new_unique_permalink;
    	update_option('permalink-manager-uris', $permalink_manager_uris);
    }
    add_action('permalink_manager_updated_post_uri', 'pm_force_unique_permalinks', 10, 3);
    add_action('permalink_manager_new_post_uri', 'pm_force_unique_permalinks', 10, 3);
    Thread Starter aceone999

    (@aceone999)

    Thx, seems to work, but doesn’t work with my front end form.

    Thread Starter aceone999

    (@aceone999)

    I use AccessPress.

    I will like to centralize “jetpack_subscription_form title” in my site, please help out.
    sorry for posting unrelated topic on this thread. I could not find create new topic. thanks

    Thread Starter aceone999

    (@aceone999)

    Just to get my anwser to this

    There is one particular reason why I made it like this. First of all, with my plugin you can edit the full permalink and not only the native slug (the native slug is always unique and cannot be assigned to more than one post/term). This feature is widely used as it allows to reuse the same slug when the full URL address is unique as a whole:

    And why not have both? The system should only ad numbers to the slug when it’s necessary.

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘One permalink can be set more than once’ is closed to new replies.