{"id":69933,"date":"2017-02-12T14:26:52","date_gmt":"2017-02-12T14:26:52","guid":{"rendered":"https:\/\/br.wordpress.org\/support\/topic\/condicao-if-e-else-nao-funciona\/"},"modified":"2017-02-12T14:28:25","modified_gmt":"2017-02-12T14:28:25","slug":"condicao-if-e-else-nao-funciona","status":"publish","type":"topic","link":"https:\/\/br.wordpress.org\/support\/topic\/condicao-if-e-else-nao-funciona\/","title":{"rendered":"Condi\u00e7\u00e3o else n\u00e3o funciona"},"content":{"rendered":"<p>Quando eu adiciono fica <strong>meusite.com\/noticias\/tech\/amd-ryzen-sera-lancado-em-marco<\/strong><\/p>\n<p>O que eu quero \u00e9 remover o ID caso n\u00e3o tenha uma categoria marcada<\/p>\n<p>Quando eu n\u00e3o adiciono nenhuma categoria a minha url fica assim: <strong>meusite.com\/noticias\/1\/olamundo<\/strong><\/p>\n<p>Como posso fazer pra retirar o id por rewrite. Algu\u00e9m poderia me ajudar, obrigado!<\/p>\n<pre><code>\nadd_filter( &#039;post_type_link&#039;, &#039;my_post_type_link2&#039;, 99, 2 );\nfunction my_post_type_link2( $post_link, $post = null ) {\n    $newlink = $post_link;\n \n    if ( !empty($post) ) {\n        $post_type = get_post_type($post-&gt;ID);\n          \n        if($post_type == &quot;noticias&quot;) {\n            $newlink = str_replace(&#039;%category%&#039;, $post-&gt;ID, $post_link);\n        } else {\n            $newlink = str_replace(&#039;%category%&#039;, &#039;&#039;, $post_link);\n        }\n    }\n     \n    return $newlink;\n}\nadd_action( &#039;generate_rewrite_rules&#039;, &#039;fix_noticias_category_pagination&#039; );\nfunction fix_noticias_category_pagination( $wp_rewrite ) {\n    unset($wp_rewrite-&gt;rules[&#039;noticias\/([^\/]+)\/page\/?([0-9]{1,})\/?$&#039;]);\n    $wp_rewrite-&gt;rules = array(\n        &#039;noticias\/?$&#039; =&gt; $wp_rewrite-&gt;index . &#039;?post_type=noticias&#039;,\n        &#039;noticias\/page\/?([0-9]{1,})\/?$&#039; =&gt; $wp_rewrite-&gt;index . &#039;?post_type=noticias&amp;paged=&#039; . $wp_rewrite-&gt;preg_index( 1 ),\n        &#039;noticias\/([^\/]+)\/page\/?([0-9]{1,})\/?$&#039; =&gt; $wp_rewrite-&gt;index . &#039;?category_name=&#039; . $wp_rewrite-&gt;preg_index( 1 ) . &#039;&amp;paged=&#039; . $wp_rewrite-&gt;preg_index( 2 ),\n    ) + $wp_rewrite-&gt;rules;\n}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-69933","topic","type-topic","status-publish","hentry","topic-tag-permalink","topic-tag-slug"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/69933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":3,"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/69933\/revisions"}],"predecessor-version":[{"id":69936,"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/69933\/revisions\/69936"}],"wp:attachment":[{"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=69933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}