I know this has been asked a million times but I am pulling out the little hair I have!

I have a custom post type called case-study (case-study.php and then linked in functions), a file called single-case-study.php and setup a post called test but I get a 404 when I go to website/case-study/test. I have tryed flush_rewrite_rules(); in my functions.php and after register_post_type('case-study' ,$args );, I have tried goingt to permalinks in the settings and saving and I have tried changing some of the things in the post register such as hierarchical or has_archive.

I have tried disabling all plugins, basically I have tried everything on this website How to Fix 404 and anything I could find on here. Does anyone know of anything else that could be casuing this?

Here is my register_post_type:

$args = array(
    'label'              => 'Case Study',
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'query_var'          => false,
    'capability_type'    => 'page',
    'hierarchical'       => true,
    'has_archive'        => false,
    'rewrite'            => array('slug' => 'case-study', 'with_front' => false),
    'supports'           => array('title', 'editor', 'thumbnail'),
    'menu_position'      => 31
register_post_type('case-study' ,$args );
  • 1
    Hi Snookian. Your problem might be the 'query_var' arg, try removing it, or setting it to 'post_type'? – Pedro Coitinho Feb 17 '17 at 11:15
  • OMG! THANK YOU! MY SAVIOUR! Out of curiosity what does that actually do? – snookian Feb 17 '17 at 11:16
  • @PedroCoitinho write an answer ;) – cybmeta Feb 17 '17 at 11:18
  • Yeah write an answer. I just looked it up at developer.wordpress.org/reference/functions/register_post_type. Had no idea that 'query_var' stops it loading at the slug. Thanks again – snookian Feb 17 '17 at 11:19

Removing 'query_var'=> false solved this. Thanks to @PedroCoitinho

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.