Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Post types giving 404

Now I know this has been covered quite a lot, but I've read previous fixes on here and haven't had any luck.

Basically my custom post types for questions are giving me 404 errors.

So far I've tried the following:

  • Setting the permalinks to default, then changing them back again.
  • Adding flush_rewrite_rules just before the register_post_type.
  • I've checked and there are no pages and posts with the same name.
  • Deleted and recreated the htaccess file.
  • adding 'rewrite' => array( 'slug' => 'question','with_front' => FALSE)
  • creating a custom permalink structure.

Code is below:

add_action( 'init', 'irt_questions_create' );

function irt_questions_create() {

$labels = array(
    'name' => _x('Questions', 'post type general name', 'your_text_domain'),
    'singular_name' => _x('Question', 'post type singular name', 'your_text_domain'),
    'add_new' => _x('Add New', 'Question', 'your_text_domain'),
    'add_new_item' => __('Add New Question', 'your_text_domain'),
    'edit_item' => __('Edit Question', 'your_text_domain'),
    'new_item' => __('New Question', 'your_text_domain'),
    'all_items' => __('All Questions', 'your_text_domain'),
    'view_item' => __('View Question', 'your_text_domain'),
    'search_items' => __('Search Questions', 'your_text_domain'),
    'not_found' =>  __('No Questions found', 'your_text_domain'),
    'not_found_in_trash' => __('No Questions found in Trash', 'your_text_domain'), 
    'parent_item_colon' => '',
    'menu_name' => __('Questions', 'your_text_domain')
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true,
    'rewrite' => array( 'slug' => _x( 'module', 'URL slug', 'your_text_domain' ) ),
    'capability_type' => 'post',
    'has_archive' => true, 
    'hierarchical' => true,
    'menu_position' => 106,
    'supports' => array( 'title', 'editor', /*'author',*/ 'thumbnail', /*'excerpt', 'comments', 'custom-fields', 'revisions',*/ 'page-attributes')
);
register_post_type('question', $args);

}
like image 555
Mark Avatar asked Feb 13 '26 06:02

Mark


1 Answers

After 3 days of trying to fix this I found out it was 'hierarchical' => true giving me the error.

As soon as I removed this line of code and then refreshed the permalinks by Setting the permalinks to default, then changing them back again problem fixed.

like image 72
Mark Avatar answered Feb 16 '26 03:02

Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!