I have the custom post types, reception_units, year_1_units, year_2_units, year_3_units, year_4_units, year_5_units, year_6_units and resources.

I want to create archives for the different post types and their activities.

So for example example.com/Units-Activities/Football would show all the unit post types for football (reception_units, year_1_units, year_2_units, year_3_units, year_4_units, year_5_units, year_6_units)

and example.com/Resources-Activities/Football would show all the resource post types for football.

How do I achieve this and how can I create a template that get's this?

I currently am trying like this:

// Custom rewrite rules
function custom_rewrite_rules() {
    // Custom rewrite rule for Units-Activities
    add_rewrite_rule('^Units-Activities/([^/]+)/?$', 'index.php?activity=$matches[1]', 'top');

    // Custom rewrite rule for Resources-Activities
    add_rewrite_rule('^Resources-Activities/([^/]+)/?$', 'index.php?post_type=resources&activity=$matches[1]', 'top');

add_action('init', 'custom_rewrite_rules');

function custom_rewrite_tags($tags) {
    $tags['activity'] = '([^/]+)';
    return $tags;

add_filter('rewrite_rules_array', 'custom_rewrite_tags');

// Flush rewrite rules on activation and deactivation
function custom_flush_rewrite_rules() {

register_activation_hook(__FILE__, 'custom_flush_rewrite_rules');
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');

And then how do I target the archives for these pages with a template? I'm using oxygen builder if that makes a difference.

  • 1
    Is there a reason all the unit types are separate post types? Why not just have a unit post type and a taxonomy to indicate the year? Then unit activities just needs to be another taxonomy. Oct 9, 2023 at 13:17


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.