简体   繁体   中英

Wordpress Custom post type and permalink

I have these two statements in my init

add_rewrite_tag('%cirrus_url%','([^&]+)');
add_rewrite_rule('^listings/([^/]*)/([^/]*)/?','index.php?pagename=$matches[1]&cirrus_url=$matches[2]','top');

Using the parse_request filter, I can see that my rule is being matched and used.

However, Wordpress is forwarding the page, so all my /vars/at/the/end are lost when the page renders.

When I output something from the query_var filter, I get a Headers already sent message, so I know that wordpress is trying to forward the page.

http://1parkplace.mysharedvision.com/dev/listings/travis-heights-test/

If you put something at the end like: http://1parkplace.mysharedvision.com/dev/listings/travis-heights-test/what-is-this/

You'll see what I mean.

Any ideas?

Figured it out

add_rewrite_tag('%cirrus_url%','([^&]+)');
add_rewrite_rule('listings/([^/]*)(/[^/]+)?$/?','index.php?cirrus_posts=$matches[1]&cirrus_url=$matches[2]','top');

My custom post type was cirrus_posts so I just looked at wordpress' <?php var_dump($wp_rewrite->wp_rewrite_rules()); ?> <?php var_dump($wp_rewrite->wp_rewrite_rules()); ?>

To see what it was doing and that let me to the right thing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM