rewrite get parameter with custom post type

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)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)