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.

I have the following URL structure:

http://localhost/wordpress/gallery?id=331

id specifies the id of the post.

gallery is a normal page inside which I am accessing the id of the post and fetching the attachment images using WP_Query().

I want to replace the URL of this page to:

http://localhost/wordpress/topic/place/new-delhi/gallery?id=331

in which the parameters place and new-delhi may vary in multiple other options and topic is the keyword which remains the same.

I have tried using some unfruitful .htaccess file code.

Can anyone please help?

share|improve this question
    
Please edit your question and tell exactly where you've set topic, place, new-delhi and what they are (custom post type/meta data/taxonomy, etc.). –  kaiser Oct 9 '12 at 12:25
    
topic is a page and place is a cpt and new-delhi is a post under 'place' cpt –  Rohit Pande Oct 9 '12 at 13:21
    
"Please edit your question(...)" –  kaiser Oct 9 '12 at 14:11

1 Answer 1

up vote 0 down vote accepted

I have tried some add_rewrite_rule magic and query variables and it worked. Thanks for the help everyone.

If in case anyone want to refer the answer:

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

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

I was able to solve my problem with this.

share|improve this answer

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.