Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As per the answer provided in How to create custom URL routes? I have created the rewrite rule using the same function provided.

add_action( 'init', 'wpse26388_rewrites_init' );
function wpse26388_rewrites_init(){
    add_rewrite_rule(
        'gallery/([0-9]+)/?$',
        'gallery?custom_gallery_id=$1',
        'top' );        
}

After the flushing of the rules .htaccess file was having the following rule :

RewriteRule ^gallery/([^/]+)/?$ /wordpress/gallery?custom_gallery_id=$1 [QSA,L]

upto this point everything was fine then I tried to make some modifications in the rule like

add_action( 'init', 'wpse26388_rewrites_init' );
    function wpse26388_rewrites_init(){
        add_rewrite_rule(
            'topic/([^/]+)/([^/]+)/gallery/([0-9]+)/?$',
            'gallery?custom_gallery_id=$3',
            'top' );        
    }

this doesn't seems to be working at all. can anybody help me over this? thanks in advance.

share|improve this question
    
the important difference between your rewrite rule and the one you linked is that the one in the other question points to a WordPress page, and doesn't result in an external rewrite in .htaccess, it's an internal rewrite handled entirely within WordPress. please amend your question to clarify exactly what you're trying to load- what are topic and gallery exactly? –  Milo Oct 17 '12 at 5:42
    
@Milo gallery is a page to which I am passing a post id of which the attachment images are needed to be fetched as a gallery. refer this link newsmirror.agstechnologies.com/gallery?id=322 –  Rohit Pande Oct 17 '12 at 5:51
    
@Milo also refer this link newsmirror.agstechnologies.com/topic/place/new-delhi this is the custom post page for which I want to create a galley page. –  Rohit Pande Oct 17 '12 at 5:55
add comment

1 Answer

up vote 1 down vote accepted

first, you need to add your custom_gallery_id to query vars if you haven't already:

add_filter( 'query_vars', 'wpse26388_query_vars' );
function wpse26388_query_vars( $query_vars ){
    $query_vars[] = 'custom_gallery_id';
    return $query_vars;
}

for your rewrite rule, you need to load a WordPress object- a page, a category, etc., and all internal rewrites must point to index.php. if topic, place, and new delhi are all pages, it would look something like this:

function wpse26388_rewrites_init(){
    add_rewrite_rule(
        'topic/([^/]+)/([^/]+)/gallery/([0-9]+)/?$',
        'index.php?pagename=topic/$matches[1]/$matches[2]&custom_gallery_id=$matches[3]',
        'top' );        
}

also try out this plugin for analyzing and testing your rewrite rules.

share|improve this answer
    
can you please elaborate more on for your rewrite rule, you need to load a WordPress object- a page, a category, etc. . Sorry I am a newbie so unable to understand in a first stroke. –  Rohit Pande Oct 17 '12 at 6:52
    
I tried adding your code but the query variable is not getting set so I am unable to access the value of custom_gallery_id on the gallery page. any suggestions? –  Rohit Pande Oct 17 '12 at 7:00
    
It worked.. thanks 4 d help... :) –  Rohit Pande Oct 17 '12 at 10:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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