plugins - flush rewrite rules doesn't flush them (still got 404)

admin2025-04-22  0

So I tried to make a simple plugin for WordPress. Like a reviews. Even tried to do it through the tutorial of TutsPlus. Everytime I got 404 when tried. Then I just took the code from tutor and still got 404 on viewing my review post type post.


    function my_custom_posttypes() {

    $labels = array(
        'name'               => 'Testimonials',
        'singular_name'      => 'Testimonial',
        'menu_name'          => 'Testimonials',
        'name_admin_bar'     => 'Testimonial',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Testimonial',
        'new_item'           => 'New Testimonial',
        'edit_item'          => 'Edit Testimonial',
        'view_item'          => 'View Testimonial',
        'all_items'          => 'All Testimonials',
        'search_items'       => 'Search Testimonials',
        'parent_item_colon'  => 'Parent Testimonials:',
        'not_found'          => 'No testimonials found.',
        'not_found_in_trash' => 'No testimonials found in Trash.',
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'menu_icon'          => 'dashicons-id-alt',
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'testimonials' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => 5,
        'supports'           => array( 'title', 'editor', 'thumbnail' )
    );
    register_post_type( 'testimonial', $args );
}
add_action( 'init', 'my_custom_posttypes' );

// Flush rewrite rules to add "review" as a permalink slug
function my_rewrite_flush() {
    my_custom_posttypes();
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_rewrite_flush' );

on top was php opening tag and plugin info (as usual). Tried it with several themes - still got 404. Before every test I saved changes on Permalinks and deactivated && activated that plugin.

Anyone got any ideas? I'm just learning for now (yesterday started).

So I tried to make a simple plugin for WordPress. Like a reviews. Even tried to do it through the tutorial of TutsPlus. Everytime I got 404 when tried. Then I just took the code from tutor and still got 404 on viewing my review post type post.


    function my_custom_posttypes() {

    $labels = array(
        'name'               => 'Testimonials',
        'singular_name'      => 'Testimonial',
        'menu_name'          => 'Testimonials',
        'name_admin_bar'     => 'Testimonial',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Testimonial',
        'new_item'           => 'New Testimonial',
        'edit_item'          => 'Edit Testimonial',
        'view_item'          => 'View Testimonial',
        'all_items'          => 'All Testimonials',
        'search_items'       => 'Search Testimonials',
        'parent_item_colon'  => 'Parent Testimonials:',
        'not_found'          => 'No testimonials found.',
        'not_found_in_trash' => 'No testimonials found in Trash.',
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'menu_icon'          => 'dashicons-id-alt',
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'testimonials' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => 5,
        'supports'           => array( 'title', 'editor', 'thumbnail' )
    );
    register_post_type( 'testimonial', $args );
}
add_action( 'init', 'my_custom_posttypes' );

// Flush rewrite rules to add "review" as a permalink slug
function my_rewrite_flush() {
    my_custom_posttypes();
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_rewrite_flush' );

on top was php opening tag and plugin info (as usual). Tried it with several themes - still got 404. Before every test I saved changes on Permalinks and deactivated && activated that plugin.

Anyone got any ideas? I'm just learning for now (yesterday started).

Share Improve this question edited Aug 5, 2015 at 0:44 davisdev asked Aug 5, 2015 at 0:37 davisdevdavisdev 113 bronze badges 4
  • 404 where? Trying to access what? – jdm2112 Commented Aug 5, 2015 at 0:45
  • Trying to view the review! Please, try to read the text first! – davisdev Commented Aug 5, 2015 at 1:00
  • screencloud/v/gQog is it clear now? – davisdev Commented Aug 5, 2015 at 1:01
  • After the edit, yes. It helps to be clear when asking a question you want an answer to. – jdm2112 Commented Aug 5, 2015 at 1:46
Add a comment  | 

1 Answer 1

Reset to default 0

It might be an .htaccess issue. Sometimes I try to flush the rewrite rules from the command line and it doesn't rewrite the .htaccess file until I go into the /wp-admin section, go to 'Settings > Permalinks' and just save it without making any modifications. See if that works.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745276661a293912.html

最新回复(0)