Condição else não funciona
-
Quando eu adiciono fica meusite.com/noticias/tech/amd-ryzen-sera-lancado-em-marco
O que eu quero é remover o ID caso não tenha uma categoria marcada
Quando eu não adiciono nenhuma categoria a minha url fica assim: meusite.com/noticias/1/olamundo
Como posso fazer pra retirar o id por rewrite. Alguém poderia me ajudar, obrigado!
add_filter( 'post_type_link', 'my_post_type_link2', 99, 2 ); function my_post_type_link2( $post_link, $post = null ) { $newlink = $post_link; if ( !empty($post) ) { $post_type = get_post_type($post->ID); if($post_type == "noticias") { $newlink = str_replace('%category%', $post->ID, $post_link); } else { $newlink = str_replace('%category%', '', $post_link); } } return $newlink; } add_action( 'generate_rewrite_rules', 'fix_noticias_category_pagination' ); function fix_noticias_category_pagination( $wp_rewrite ) { unset($wp_rewrite->rules['noticias/([^/]+)/page/?([0-9]{1,})/?$']); $wp_rewrite->rules = array( 'noticias/?$' => $wp_rewrite->index . '?post_type=noticias', 'noticias/page/?([0-9]{1,})/?$' => $wp_rewrite->index . '?post_type=noticias&paged=' . $wp_rewrite->preg_index( 1 ), 'noticias/([^/]+)/page/?([0-9]{1,})/?$' => $wp_rewrite->index . '?category_name=' . $wp_rewrite->preg_index( 1 ) . '&paged=' . $wp_rewrite->preg_index( 2 ), ) + $wp_rewrite->rules; }
- O tópico ‘Condição else não funciona’ está fechado para novas respostas.