• Resolved killjack

    (@killjack)


    Hello. Scenario: I want to display the listing grid of a portfolio plugin on my website, but I want to change the link of the posts to lead to an already created page. If I change it via a real time Find & Replace, it works for the first few posts, but after browsing in ajax it stops working.

    So using your plugin, I left the link of the posts the same as the page, but it didn’t work either, since now the listing opens the posts and not the pages already created with the same link.

    Your plugin seems well rated, but I haven’t found a quick way to restore the site’s default settings before I’ve changed the slugs. There is a way?

    It was also not clear from your documentation what kind of changes your plugin makes to the system. If everything goes back to normal when I deactivate the plugin, or if the changes will still continue. It seems that it doesn’t restore the default after deactivation.

    By the way, is there a way with your plugin to achieve what I want in the scenario I mentioned? I’m wondering if a Find & Replace on the database will work, but this is a sensitive and irreversible change, so kindly enlighten me if you can, thanks!

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

    (@mbis)

    Hi @killjack,

    To put it simply, the built-in permalink system is based on native slugs (“post_name” attribute of WP_Post object) and rewrite rules. Permalink Manager bypasses this system using a more sophisticated solution by storing all custom permalinks in a separate array in the wp_options database table.

    The plugin must be enabled for the custom permalinks to take effect. Therefore, the function that replaces the inbuilt permalink with default ones is turned off when the plugin is deactivated.

    As long as you didn’t use the “Native slugs” mode, you may undo all the changes you did with my plugin by just deactivating it. The “native slugs” option was introduced to the plugin to allow users who do not want to use custom permalinks (and the plugin itself in long-term) but simply want to bulk change the native slugs and then deactivate the plugin (to keep using the inbuilt permalink system).

    Please note that there is only one comment/instruction presented in the “Find & replace” tool, and it explicitly suggests creating a backup before using “native slugs” mode:

    To “merge” two content kinds into one is a non-standard situation that requires a customised solution to make it function the way you want.

    Could you please send me some sample URLs? There is a possibility I have a ready solution.

    Plugin Author Maciej Bis

    (@mbis)

    You can force URL Manager to prioritize one specific post type above others (assuming the same URL is used by both “post” and “page”).

    function pm_control_duplicates( $excluded, $element_object, $old_query, $pm_query ) {
    	global $permalink_manager_uris;
    
    	// Which post type should be prioritized above others?
    	$priority_post_type = 'page';
    
    	// Check if there are any other items with the same custom permalink
    	if ( ! empty( $pm_query['uri'] ) && ! empty( $element_object->ID ) ) {
    		$uri = $pm_query['uri'];
    
    		// Get IDs of other content items
    		$ids = array_keys( $permalink_manager_uris, $uri );
    
    		$duplicate_has_priority_post_type = false;
    
    		// Check if any of duplicated posts belongs to priority "post_type"
    		foreach ( $ids as $id ) {
    			if ( ! is_numeric( $id ) ) {
    				continue;
    			}
    
    			$post_type = get_post_type( $id );
    
    			if ( $post_type == $priority_post_type ) {
    				$duplicate_has_priority_post_type = true;
    				break;
    			}
    		}
    
    		// If the detected custom permalink is used by both priority "post_type" and another content_type exclude it from the detect function
    		if ( $element_object->post_type !== $priority_post_type && $duplicate_has_priority_post_type ) {
    			$excluded = $element_object->ID;
    		}
    	}
    
    	return $excluded;
    }
    add_filter( 'permalink_manager_excluded_element_id', 'pm_control_duplicates', 10, 4 );
    Thread Starter killjack

    (@killjack)

    Hello. Thank you very much for your kind help, your code helped. But let me say one thing:

    Without your plugin installed, when I put a regex rule to redirect from a slug to another (^/portfolio/ to /), it works perfectly. With your plugin installed, the posts now have some type of priority, and the same redirection now opens the posts instead of pages.

    Your code works, but it makes the page load slow, probably due to the number of redirections. Is there a smooth way to do this?

    I would like to keep using your plugin as it is very useful to have same posts types with different slugs.

    • This reply was modified 1 year ago by killjack.
    Thread Starter killjack

    (@killjack)

    I tried now removing my redirect and changing the post slug using just your code, and it didn’t work, it kept opening the post instead the page. Should I change something in the code for the post type I’m using? (It’s a custom post type)

    Thread Starter killjack

    (@killjack)

    Testing…

    • This reply was modified 1 year ago by killjack.
    • This reply was modified 1 year ago by killjack.
    • This reply was modified 1 year ago by killjack.

    @mbis Hi
    Is there a way that we can prevent the admin for creating duplicate URLs

    Example :

    If there is already a URL with

    https://example.com/job/testing

    And admin wants to create a new job with same URL by using Permalink Manager Lite
    Except for showing (Permalink is already in use, please select another one!)
    Dont allow to create the same URL

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Posts with the same page URL’ is closed to new replies.