Skip to main content
1 of 2
Sally CJ
  • 39.9k
  • 2
  • 26
  • 48

The error 404 happens because you haven't registered the %school% rewrite tag — you need to register it so that WordPress will know what to replace it with when generating the rewrite rules — i.e. it doesn't remain as %school% in the generated rewrite rules. And you can register the tag using add_rewrite_tag():

// Add this to custom_post_agenda(), before you call register_post_type().
add_rewrite_tag( '%school%', '([^/]+)' );

Secondly, when you register the post type, the has_archive should be set to a unique slug such as agendas and not just true because if you use 'has_archive' => true, the archive slug would be %school%:

register_post_type( 'agenda', array(
    'has_archive' => 'agendas',
    // ...
) );

And third, because the post type's rewrite slug starts with the ([^/]+) (i.e. a category slug), you need the following filter to remove unnecessary rewrite rules (for that post type) which will conflict with Page's (and possibly other post types' and/or taxonomies') rewrite rules:

// Add this after custom_post_agenda() or somewhere else where appropriate.
add_filter( 'agenda_rewrite_rules', function( $rules ){
    // Remove all rules which don't have "/agenda/".
    unset( $rules['([^/]+)/page/?([0-9]{1,})/?$'] );
    unset( $rules['([^/]+)/comment-page-([0-9]{1,})/?$'] );
    unset( $rules['([^/]+)/?$'] );

    return $rules;
} );
Sally CJ
  • 39.9k
  • 2
  • 26
  • 48