set_permalink_structure example

// Unable to use update_network_option() while populating the network.         $wpdb->insert(
            $wpdb->sitemeta,
            array(
                'site_id'    => $network_id,
                'meta_key'   => 'main_site',
                'meta_value' => $current_site->blog_id,
            )
        );

        if ( $subdomain_install ) {
            $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
        } else {
            $wp_rewrite->set_permalink_structure( '/blog/%year%/%monthnum%/%day%/%postname%/' );
        }

        flush_rewrite_rules();

        if ( ! $subdomain_install ) {
            return true;
        }

        $vhost_ok = false;
        
$permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );

            if ( $index_php_prefix && $blog_prefix ) {
                $permalink_structure = $index_php_prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
            } else {
                $permalink_structure = $blog_prefix . $permalink_structure;
            }
        }

        $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure );

        $wp_rewrite->set_permalink_structure( $permalink_structure );

        $structure_updated = true;
    }

    if ( isset( $_POST['category_base'] ) ) {
        $category_base = $_POST['category_base'];

        if ( ! empty( $category_base ) ) {
            $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
        }

        

    $permalink_structures = array(
        '/%year%/%monthnum%/%day%/%postname%/',
        '/index.php/%year%/%monthnum%/%day%/%postname%/',
    );

    foreach ( (array) $permalink_structures as $permalink_structure ) {
        $wp_rewrite->set_permalink_structure( $permalink_structure );

        /* * Flush rules with the hard option to force refresh of the web-server's * rewrite config file (e.g. .htaccess or web.config). */
        $wp_rewrite->flush_rules( true );

        $test_url = '';

        // Test against a real WordPress post.         $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
        
Home | Imprint | This part of the site doesn't use cookies.