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 am trying now for a couple days to solve the following Problem:

I have a custom post type called gallery. I need the URL

http://example.com/gallery/FOOBAR

to be parsed like

http://example.com/gallery/?param=FOOBAR

The Permalink Setting for custom post type is:

/gallery/%postname%/%year%/%monthnum%/%day%/

I think I have tried about every code snipped that I could find to solve this problem but nothing seems to work.
If I flush all rewrites, none of my links work anymore (404)

Is is even possible?

share|improve this question

1 Answer 1

I think it should work. First you need to register your rewrite rule and the parameter:

function my_init() {
    add_rewrite_rule(
        'gallery/(.+?)/?$',
        'index.php?post_type=gallery&param=$matches[1]',
        'top' );
    add_rewrite_tag('%param%','([^&]+)');
}
add_action('init', 'my_init');

Then you can read the parameter value from the query:

$param = get_query_var('param');

Don't forget to flush the rewrites. (just view the rewrite settings page to flush the rules)

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.