Wordpress自定义Post Type:Post url中的Post ID
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress自定义Post Type:Post url中的Post ID相关的知识,希望对你有一定的参考价值。
so you want to have your url structure like :yourdomain.com/post-type/286
add the following snippet to your functions.php and change the post-type names where appropriate
add_action('init', 'post-type_rewrite'); function post-type_rewrite() { global $wp_rewrite; $queryarg = 'post_type=post-type&p='; $wp_rewrite->add_rewrite_tag('%post_id%', '([^/]+)', $queryarg); $wp_rewrite->add_permastruct('post-type', '/post-type/%post_id%', false); } add_filter('post_type_link', 'post-type_permalink', 1, 3); function post-type_permalink($post_link, $id = 0, $leavename, $sample) { global $wp_rewrite; $post = &get_post($id); if ( is_wp_error( $post ) ) return $post; $newlink = $wp_rewrite->get_extra_permastruct('bodumanzaru'); $newlink = home_url(user_trailingslashit($newlink)); return $newlink; }
以上是关于Wordpress自定义Post Type:Post url中的Post ID的主要内容,如果未能解决你的问题,请参考以下文章