• Resolved kirgizmustafa17

    (@kirgizmustafa17)


    I am using wp-cli and I try to change my post’s permalinks with wp-cli but I did not make it. Anyone know that how can I do?

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

    (@mbis)

    Hi @kirgizmustafa17,

    unfortunately it is not available in the vanilla version of plugin, but you can try to use the following code snippet to make it possible to set custom permalinks with CLI:

    /**
     * Examples:
     * 1. wp set_custom_permalink --id=123 --uri="sample/custom/permalink"
     * 2. wp set_custom_permalink --id=123 --uri="default"
     */
    function pm_set_custom_uri($args = array(), $assoc_args = array()) {
    	global $permalink_manager_uris;
    	
    	$arguments = wp_parse_args(
    		$assoc_args,
    		array(
    			'id'    => 0,
    			'uri' => '',
    		)
    	);
    
    	// Check if arguments are alright.
    	if(!empty($arguments['id']) && ! empty($arguments['uri']) && !empty($permalink_manager_uris)) {
    		$post_id = $arguments['id'];
    		$post_uri = ($arguments['uri'] == 'default') ? Permalink_Manager_URI_Functions_Post::get_default_post_uri($post_id) : $arguments['uri'];
    		
    		$permalink_manager_uris[$post_id] = $post_uri;
    		update_option('permalink-manager-uris', $permalink_manager_uris);
    
    		// Show success message.
    		WP_CLI::success('The custom permalink was set correctly!');
    	} else {
    		// Show error message
    		WP_CLI::error('The custom permalink was not set!' );
    	}
    }
    
    if(defined( 'WP_CLI' ) && WP_CLI) {
    	WP_CLI::add_command('set_custom_permalink', 'pm_set_custom_permalink');
    }

    Best regards,
    Maciej

    Thread Starter kirgizmustafa17

    (@kirgizmustafa17)

    Thank you for you answer. I am trying now,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is it possible using this plugin with wp-cli’ is closed to new replies.