I have a custom post type called Content, that has a capability type of 'page' and is set to 'hierarchical' => true. I have two pages with the same name "Children", but they have different parents. What should i be doing differently so that WP doesnt display both of them at the same time no matter which of the two urls i go to? Here is a snippet of my code that displays the rewrite rules:

add_filter('rewrite_rules_array', 'mmp_rewrite_rules');
    function mmp_rewrite_rules($rules) {
        $newRules  = array();
        $newRules['content/(.+)/(.+)/?$'] = 'index.php?content=$matches[2]'; 
        $newRules['content/(.+)/?$']      = 'index.php?campus=$matches[1]'; 

        return array_merge($newRules, $rules);

    function filter_post_type_link($link, $post)
        if ($post->post_type != 'content')
            return $link;

        if ($cats = get_the_terms($post->ID, 'campus'))
            $link = str_replace('%campus%', get_taxonomy_parents(array_pop($cats)->term_id, 'campus', false, '', true), $link); // see custom function defined below
        return $link;
    add_filter('post_type_link', 'filter_post_type_link', 10, 2);

    // my own function to do what get_category_parents does for other taxonomies
    function get_taxonomy_parents($id, $taxonomy, $link = false, $separator = '/', $nicename = false, $visited = array()) {    
        $chain = '';   
        $parent = &get_term($id, $taxonomy);

        if (is_wp_error($parent)) {
            return $parent;

        if ($nicename)    
            $name = $parent -> slug;        
            $name = $parent -> name;

        if ($parent -> parent && ($parent -> parent != $parent -> term_id) && !in_array($parent -> parent, $visited)) {    
            $visited[] = $parent -> parent;    
            $chain .= get_taxonomy_parents($parent -> parent, $taxonomy, $link, $separator, $nicename, $visited);


        if ($link) {
            // nothing, can't get this working :(
        } else    
            $chain .= $name . $separator;    
        return $chain;    

The two urls are like so:



When going to either one of those urls, it should only be the content of that particular 'page' and not the contents of both on the same page.

Any suggestions? Im assuming the $newRules area needs to be redone.

1 Answer 1


I'm not really sure whats going on here - havent done too much with rewrites like this.

But should this:

$newRules['content/(.+)/(.+)/?$'] = 'index.php?content=$matches[2]'; 
$newRules['content/(.+)/?$']      = 'index.php?campus=$matches[1]'; 

Be This?:

$newRules['content/(.+)/(.+)/(.+)/?$'] = 'index.php?content=$matches[3]'; 
$newRules['content/(.+)/(.+)/?$']      = 'index.php?campus=$matches[2]'; 

To Match:



  • Well actually this code ended up working: pastie.org/private/73fxmsa1afzxnnpsfnfp6q, but for some reason no matter what, the flush rules happens and if I disable that action, the rules dont seem to apply and I get 404's again. =/ Flushing the rules should only need to be done once. No idea why they arent becoming permanent. Jun 22, 2012 at 8:02

Your Answer

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

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