1

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

http://127.0.0.1/CONSTRUCTION/wordpress/%postname%/

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;
}
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');

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

?realisation=habillage-de-stands&parentid=38

with rewriting i would like to have :

realisation/habillage-de-stands/38

but instead i get :

realisation/habillage-de-stands/&parentid=0/

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 :

realisation/habillage-de-stands/38

this is well matched with my rule, but

realisation/habillage-de-stands/&parentid=0/

also. for instance the

realisation/habillage-de-stands/38

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

&parentid=0

whereas without rewriting i get

38

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.

Thanks

---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 :

?page_id=38 

when i

echo get_query_var( 'page_id' ); 

or

echo get_query_var( 'p' ); 

or

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

or

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 ?

0

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.