://forum/15-nom-categorie-arbitraire/ $url = $_SERVER['REQUEST_URI']; $pattern = "/^\\/forum\\/(\\d+)[a-z0-9-_]*/i"; if ( preg_match( $pattern, $url, $matches ) ) { $ancien_id = $matches[1]; $type = 'forum'; $metakey = '_ancien_id_forum'; // Y-a-t’il un contenu correspondant ? $post = get_posts( array( 'posts_per_page' => 1, 'suppress_filters' => false, 'no_found_rows' => '1', 'post_type' => $type, 'meta_query' => array( 'relation' => 'AND', array( 'key' => $metakey, 'value' => $ancien_id, 'compare' => '=', ) ), ) ); if ( ! empty( $post ) ) { // Oui : on redirige ! wp_redirect( get_permalink( $post[0] ), '301' ); exit(); } } } }