I have many issues with the use of rewriting, but i'll just point out one in this post to be specific.

In my theme i use custom post type, with custom taxonomy

function custom_post_realisation() {
    $labels = array(
        'name' => 'realisation',
        'menu_name' => 'Realisation'
    $args = array(
        'labels' => $labels,
        'public' => true,
        'show_in_nav_menus' => true,
        'menu_position' => 5,
        'show_ui' => true,
        'show_in_menu' => true, 
        'capability_type' => 'post',
        'hierarchical' => true,
        'with_front' => false,
        'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
        'has_archive' => false,
    register_post_type( 'realisation', $args );
add_action( 'init', 'custom_post_realisation' );
function taxonomies_realisation() {
    $args = array( 
        'hierarchical' => true, 
        'label' => 'realisation', 
        'query_var' => true, 
        'rewrite' => true, 
        'show_admin_column' => true ,
    register_taxonomy( 'realisation_category', 'realisation',  $args);
add_action( 'init', 'taxonomies_realisation', 0 );

For breadcrumb purposes i use an extra parameter in my permalinks : parentid

Everything works fine without rewriting.

In the permaling management i set

And in order to use this extra parameter in the rewrite string i have added in functions.php

function add_query_vars($query_vars)
    $query_vars[] = "parentid";
    return $query_vars;
add_filter('query_vars', 'add_query_vars');
// Adding a new rule
function wp_insertMyRewriteRules($rules)
    $newrules = array();
    $newrules['realisation/([^/]+)/([^/]+)$'] = 'index.php?realisation=$matches[1]&parentid=$matches[2]';
    return $newrules + $rules;

without rewriting, i have for custom post type 'realisation' article


with rewriting i would like to have :


but instead i get :


This doesn't lead to a 404, but :

  • this is not the desired permalink
  • the parentid value is lost ! (0 != 38)

Why &parentid is still in the rewritten string ? Why the parentid is lost ? I've never heard of such thing using a rewriting.

to be more precise : i tried this tool : http://wordpress.org/extend/plugins/monkeyman-rewrite-analyzer/ and if i try in the tool this pattern :


this is well matched with my rule, but


also. for instance the


gives me in the tool

realisation/([^/]+)/([^/]+)/?   => realisation: habillage-de-stands, parentid: 38
realisation/(.+?)(/[0-9]+)?/?$  => realisation: habillage-de-stands, page: /38
(.?.+?)(/[0-9]+)?/?$            => pagename: realisation/habillage-de-stands, page: /38

And another point: wether i get my parameter like this

$parentid = $wp_query->query_vars['parentid']; 

or this

$parentid = get_query_var( 'parentid');

with the rewriting, if i echo $parentid, i get


whereas without rewriting i get


So i'm not sure if it's only a pattern problem or a more complex one, affecting the way query vars are retrieved when rewrite is set.


---EDIT ---

I think there's something wrong (or something i totally don't understand) with the rewriting thing.

For instance a parent, simple page, with no extra parameter : without rewriting :


when i

echo get_query_var( 'page_id' ); 


echo get_query_var( 'p' ); 


echo $wp_query->query_vars['page_id']; 


echo $wp_query->query_vars['p']; 

The displayed result is '38', as expected.

But if i turn on the rewrite, all the previous queries return 0 !

why do i "loose" the query value when rewriting ?


Your Answer

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

Browse other questions tagged or ask your own question.