Forums

Custom Post Type Permalink Returns 404 Error (2 posts)

  1. imageac
    Member
    Posted 9 months ago #

    Hi,

    During WP 3.3.2, single-products.php was serving ' products ' custom post type. Since, I upgraded WordPress version from 3.3.2 to 3.4.1, I discovered permalink returns 404 error on Custom post type ' products '.

    After adding following code in functions.php, it doesn't return 404 error, but redirect to homepage and still reluctant to serve requested content.

    function produc_rewrite() {
        global $wp_rewrite;
    
        $wp_rewrite->add_permastruct('products', 'products/%postname%/', true, 1);
    
        add_rewrite_rule('products/([^/]+)/?$', 'index.php?post_type=products&postname=$matches[1]', 'top');
    
        $wp_rewrite->flush_rules(false); // !!!
    }
    add_action('init', 'produc_rewrite');

    I also have tried to disable all plugin and deactivated current theme to default theme 'twentyeleven', but nothing fruitful. Please assist me to recover my content for ' products ' custom post type.

    Regards

  2. zex2911
    Member
    Posted 9 months ago #

    Can you use pastebin and display here the code for your custom post? It can be that you have a rewrite problem. In your array (under a function for register custom post) find the line with rewrite rule, and it should look something like this

    'rewrite' => array( 'slug' => 'product', 'with_front' => true ),

    You should also include this line after register_post_type line

    flush_rewrite_rules();

    after that, refresh your site, check is it working and delete or comment out flush_rewrite_rules line. Hope that helps.

Reply

You must log in to post.

About this Topic