2

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);

}
6
  • Do any type of "pretty permalinks" work, or is the issue specific to CPTs? If all pretty permalinks are broken you probably need to enable mod_rewrite in your Apache configuration.
    – Ennui
    May 15, 2013 at 14:56
  • Also, try simply removing the rewrite parameter from $args (it will default to true and use your post type slug question for rewrite) and see if that changes anything.
    – Ennui
    May 15, 2013 at 14:59
  • Thanks for the reply, all the other permalinks work its just these specific ones that dont. I will try removing the rewrite perameter and see if that makes any difference.
    – Mark
    May 15, 2013 at 15:45
  • Removing the slug for rewrite didnt work, still 404. Thanks anyway.
    – Mark
    May 15, 2013 at 15:52
  • That's odd. I'm not sure I can help much further without really being able to dig into it myself, there's probably something else conflicting with the rewrite rules. Maybe try using one of the CPT management plugins (Types is one I use a lot)?
    – Ennui
    May 15, 2013 at 17:17

2 Answers 2

6

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.

1
  • What if i have a hierarchical post type and i can not remove that ?? May 11, 2017 at 5:16
3

In Actual, you need to update your permalinks after creating new custom post, 'hierarchical' => 'true' it won't affect the 404 error. just going to permalinks and save it again made it in flow.

1
  • Thanks for the suggestion but at the time I did update the permalinks after creating a new customer post. This did not make any difference and the only way I managed to resolve this error was to remove 'hierarchical' => true.
    – Mark
    Jun 27, 2016 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.