/** * Filter the post type archive permalink. * * @since 3.1.0 * * @param string $link The post type archive permalink. * @param string $post_type Post type name. * * @return string */ public function post_type_archive_link($link, $post_type) { $post_type_obj = get_post_type_object($post_type); if (get_option('permalink_structure') && is_array($post_type_obj->rewrite)) { $struct = $this->option->get_front_struct($post_type); $link = home_url(user_trailingslashit($struct, 'post_type_archive')); } return $link; }
/** * after a post type is registered. * * @param string $post_type Post type. * @param object $args Arguments used to register the post type. */ public function register_rewrite_rule($post_type, $args) { if ('' == get_option('permalink_structure')) { return; } $permastruct_args = $args->rewrite; $permastruct_args['feed'] = $permastruct_args['feeds']; $queryarg = "post_type={$post_type}&p="; $tag = "%{$post_type}_id%"; add_rewrite_tag($tag, '([0-9]+)', $queryarg); if ($struct = $this->option->get_structure($post_type)) { $search = array('%postname%', '%post_id%'); $replace = array("%{$post_type}%", "%{$post_type}_id%"); $struct = str_replace($search, $replace, $struct); add_permastruct($post_type, $struct, $permastruct_args); $slug = $this->option->get_front_struct($post_type); if ($slug) { add_rewrite_rule("{$slug}/page/?([0-9]{1,})/?\$", "index.php?paged=\$matches[1]&post_type={$post_type}", 'top'); add_rewrite_rule("{$slug}/?\$", "index.php?post_type={$post_type}", 'top'); } } }