{"id":81343,"date":"2018-08-30T16:25:22","date_gmt":"2018-08-30T16:25:22","guid":{"rendered":"https:\/\/br.wordpress.org\/support\/topic\/custom-type-e-novo-taxonomy-exibir-registros-apenas-da-categoria-selecionada\/"},"modified":"2018-08-30T23:09:14","modified_gmt":"2018-08-30T23:09:14","slug":"custom-type-e-novo-taxonomy-exibir-registros-apenas-da-categoria-selecionada","status":"closed","type":"topic","link":"https:\/\/br.wordpress.org\/support\/topic\/custom-type-e-novo-taxonomy-exibir-registros-apenas-da-categoria-selecionada\/","title":{"rendered":"Custom Type e Novo Taxonomy &#8211; Exibir registros apenas da categoria selecionada"},"content":{"rendered":"<p>Boa tarde!<\/p>\n<p>Criei um register_post_type chamado &#8220;downloads&#8221; e criei categorias para estas utilizando o register_taxonomy() chamado downloads-category.<\/p>\n<p>No WP-Admin, consegui cadastrar todos meus arquivos e separar eles por categorias. Est\u00e1 funcioando direitinho. Por\u00e9m, no site, n\u00e3o consegui fazer essa filtragem. Se verem no link que enviei (https:\/\/ideia.marfin.co\/downloads\/), ao clicar em qualquer categoria, nenhum filtro \u00e9 realizado.<\/p>\n<p>N\u00e3o sei aonde errei! Podem me ajudar?<\/p>\n<p><strong>functions.php<\/strong><\/p>\n<pre><code>register_post_type(&#039;downloads&#039;,\n    array(\n        &#039;labels&#039; =&gt; array(\n            &#039;name&#039; =&gt; __(&#039;Downloads&#039;),\n            &#039;featured_image&#039; =&gt; __(&#039;Imagem Capa&#039;),\n            &#039;singular_name&#039; =&gt; __(&#039;Download&#039;),\n        ),\n        &#039;taxonomies&#039;  =&gt; array(&#039;downloads-category&#039;),\n        &#039;supports&#039; =&gt; array(\n        \t&#039;title&#039;,\n        \t&#039;editor&#039;,\n        \t&#039;custom-fields&#039;,\n        \t&#039;thumbnail&#039;\n        ),\n        &#039;menu_icon&#039;   =&gt; &#039;dashicons-category&#039;,\n        &#039;with_front&#039; =&gt; true,\n        &#039;public&#039; =&gt; true,\n        &#039;has_archive&#039; =&gt; true,\n        &#039;rewrite&#039; =&gt; array(&#039;slug&#039; =&gt; &#039;downloads&#039;),\n    )\n);\n$labels = array(\n\t&#039;name&#039; =&gt; _x(&#039;Categorias&#039;, &#039;taxonomy general name&#039;),\n\t&#039;singular_name&#039; =&gt; _x(&#039;Categoria&#039;, &#039;taxonomy singular name&#039;),\n\t&#039;search_items&#039; =&gt;  __(&#039;Procurar categoria&#039;),\n\t&#039;all_items&#039; =&gt; __(&#039;Todos&#039;),\n\t&#039;edit_item&#039; =&gt; __(&#039;Editar categoria&#039;), \n\t&#039;update_item&#039; =&gt; __(&#039;Editar categoria&#039;),\n\t&#039;add_new_item&#039; =&gt; __(&#039;Adicionar categoria&#039;),\n\t&#039;new_item_name&#039; =&gt; __(&#039;Nova categoria&#039;)\n);    \nregister_taxonomy(&#039;downloads-category&#039;,array(&#039;downloads&#039;), array(\n\t&#039;hierarchical&#039; =&gt; true,\n\t&#039;labels&#039; =&gt; $labels,\n\t&#039;show_ui&#039; =&gt; true,\n\t&#039;query_var&#039; =&gt; true,\n\t&#039;show_in_nav_menus&#039; =&gt; true,\n\t&#039;rewrite&#039; =&gt; array(&#039;slug&#039; =&gt; &#039;categoria-de-downloads&#039;, &#039;with_front&#039; =&gt; false),\n));<\/code><\/pre>\n<p><strong>archive.php<\/strong><\/p>\n<pre><code>&lt;?php get_header(); ?&gt;\n&lt;?php if(is_post_type_archive(&#039;downloads&#039;)){ ?&gt;\n&lt;section id=&quot;conteudo&quot;&gt;\n    &lt;div class=&quot;title&quot;&gt;\n        &lt;div class=&quot;container&quot;&gt;\n        \t&lt;h1&gt;Downloads&lt;\/h1&gt;\n        \t&lt;?php if (function_exists(&#039;yoast_breadcrumb&#039;)){ yoast_breadcrumb(&#039;&lt;p id=&quot;breadcrumbs&quot;&gt;&#039;,&#039;&lt;\/p&gt;&#039;); }?&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n    &lt;div class=&quot;content-master&quot;&gt;\n    \t&lt;div class=&quot;container&quot;&gt;\n    \t\t&lt;div class=&quot;row more-gutter&quot;&gt;\n    \t\t\t&lt;aside class=&quot;col-sm-3&quot;&gt;\n    \t\t\t\t&lt;?php\n\n    \t\t\t\t\t$args = array(\n\t\t\t\t\t\t    &#039;orderby&#039; =&gt; &#039;name&#039;,\n\t\t\t\t\t\t    &#039;taxonomy&#039;=&gt;&#039;downloads-category&#039;,\n\t\t\t\t\t\t    &#039;parent&#039; =&gt; 0\n\t\t\t\t\t\t);\n\t\t\t\t\t\t$categories = get_categories($args);\n\t\t\t\t\t\tforeach ($categories as $category){\n\t\t\t\t\t\t    echo &#039;&lt;li&gt;&lt;a href=&quot;&#039;.get_category_link($category-&gt;term_id).&#039;&quot;&gt;&#039;.$category-&gt;name.&#039;&lt;\/a&gt;&lt;\/li&gt;&#039;;\n\t\t\t\t\t\t}\n\n    \t\t\t\t?&gt;\n    \t\t\t&lt;\/aside&gt;\n    \t\t\t&lt;div class=&quot;col-sm-9&quot;&gt;\n    \t\t\t\t&lt;?php \n    \t\t\t\t\t$paged = (get_query_var(&#039;paged&#039;)) ? get_query_var(&#039;paged&#039;) : 1;\n\t\t\t\t\t\t$infoDownload = array(\n\t\t\t\t\t\t\t&#039;post_type&#039; =&gt; &#039;downloads&#039;, \n\t\t\t\t\t\t\t&#039;paged&#039; =&gt; $paged\n\t\t\t\t\t\t);\n\t\t\t\t\t\t$resultadoDownload = new WP_Query($infoDownload); \n\t\t\t\t\t\tif ($resultadoDownload-&gt;have_posts()) :\n\t\t\t\t\t\twhile ($resultadoDownload-&gt;have_posts()) : $resultadoDownload-&gt;the_post();\n\t\t\t\t\t\t\t$postThumb = (has_post_thumbnail()) ? get_the_post_thumbnail_url() : get_stylesheet_directory_uri().&quot;\/img\/layout\/sem-imagem.jpg&quot;;\n\t\t\t\t\t\t\t$postThumb = &quot;&lt;img src=\\&quot;&quot;.$postThumb.&quot;\\&quot; class=\\&quot;img-fluid\\&quot;&gt;&quot;;\n\t\t\t\t\t\t?&gt;\n\t\t\t    \t\t&lt;div class=&quot;row lista-download&quot;&gt;\n\t\t\t    \t\t\t&lt;div class=&quot;col-sm-4&quot;&gt;\n\t\t\t\t\t\t\t\t&lt;?php echo $postThumb; ?&gt;\n\t\t\t\t\t\t\t&lt;\/div&gt;\n\t\t\t\t\t\t\t&lt;div class=&quot;col-sm-8&quot;&gt;\n\t\t\t\t\t\t\t\t&lt;h3&gt;&lt;?php the_title() ?&gt;&lt;\/h3&gt;\n\t\t\t\t\t\t\t\t&lt;?php the_content(); ?&gt;\n\t\t\t\t\t\t\t&lt;\/div&gt;\n\t\t\t\t\t\t&lt;\/div&gt;\n\t\t        \t&lt;?php \n\t\t\t\t\t\twp_reset_postdata();\n\t\t\t\t\t\tendwhile;\n\t\t\t\t\t\twpbs_pagination();\n\t\t\t\t\t\tendif;\n\t\t\t\t\t?&gt;\n    \t\t\t&lt;\/div&gt;\n    \t\t&lt;\/div&gt;\n    \t&lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/section&gt;\n&lt;?php }elseif(is_tax(&#039;downloads-category&#039;)){ ?&gt;\n&lt;section id=&quot;conteudo&quot;&gt;\n    &lt;div class=&quot;title&quot;&gt;\n        &lt;div class=&quot;container&quot;&gt;\n        \t&lt;h1&gt;Nome da categoria&lt;\/h1&gt;\n        \t&lt;?php if (function_exists(&#039;yoast_breadcrumb&#039;)){ yoast_breadcrumb(&#039;&lt;p id=&quot;breadcrumbs&quot;&gt;&#039;,&#039;&lt;\/p&gt;&#039;); }?&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n    &lt;div class=&quot;content-master&quot;&gt;\n    \t&lt;div class=&quot;container&quot;&gt;\n    \t\t&lt;div class=&quot;row more-gutter&quot;&gt;\n    \t\t\t&lt;aside class=&quot;col-sm-3&quot;&gt;\n    \t\t\t\t&lt;?php\n\n    \t\t\t\t\t$args = array(\n\t\t\t\t\t\t    &#039;orderby&#039; =&gt; &#039;name&#039;,\n\t\t\t\t\t\t    &#039;taxonomy&#039;=&gt;&#039;downloads-category&#039;,\n\t\t\t\t\t\t    &#039;parent&#039; =&gt; 0\n\t\t\t\t\t\t);\n\t\t\t\t\t\t$categories = get_categories($args);\n\t\t\t\t\t\tforeach ($categories as $category){\n\t\t\t\t\t\t    echo &#039;&lt;li&gt;&lt;a href=&quot;&#039;.get_category_link($category-&gt;term_id).&#039;&quot;&gt;&#039;.$category-&gt;name.&#039;&lt;\/a&gt;&lt;\/li&gt;&#039;;\n\t\t\t\t\t\t}\n\n    \t\t\t\t?&gt;\n    \t\t\t&lt;\/aside&gt;\n    \t\t\t&lt;div class=&quot;col-sm-9&quot;&gt;\n    \t\t\t\t&lt;?php \n    \t\t\t\t\t$paged = (get_query_var(&#039;paged&#039;)) ? get_query_var(&#039;paged&#039;) : 1;\n\t\t\t\t\t\t$infoDownload = array(\n\t\t\t\t\t\t\t&#039;post_type&#039; =&gt; &#039;downloads&#039;,\n\t\t\t\t\t\t\t&#039;tax_query&#039; =&gt; array(\n\t\t\t\t\t\t        array(\n\t\t\t\t\t\t            &#039;taxonomy&#039;=&gt;&#039;downloads-category&#039;,\n\t\t\t\t\t\t            &#039;field&#039;    =&gt; &#039;slug&#039;\n\t\t\t\t\t\t        )\n\t\t\t\t\t\t    ),\n\t\t\t\t\t\t\t&#039;paged&#039; =&gt; $paged\n\t\t\t\t\t\t);\n\t\t\t\t\t\t$resultadoDownload = new WP_Query($infoDownload); \n\t\t\t\t\t\tif ($resultadoDownload-&gt;have_posts()) :\n\t\t\t\t\t\twhile ($resultadoDownload-&gt;have_posts()) : $resultadoDownload-&gt;the_post();\n\t\t\t\t\t\t\t$postThumb = (has_post_thumbnail()) ? get_the_post_thumbnail_url() : get_stylesheet_directory_uri().&quot;\/img\/layout\/sem-imagem.jpg&quot;;\n\t\t\t\t\t\t\t$postThumb = &quot;&lt;img src=\\&quot;&quot;.$postThumb.&quot;\\&quot; class=\\&quot;img-fluid\\&quot;&gt;&quot;;\n\t\t\t\t\t\t?&gt;\n\t\t\t    \t\t&lt;div class=&quot;row lista-download&quot;&gt;\n\t\t\t    \t\t\t&lt;div class=&quot;col-sm-4&quot;&gt;\n\t\t\t\t\t\t\t\t&lt;?php echo $postThumb; ?&gt;\n\t\t\t\t\t\t\t&lt;\/div&gt;\n\t\t\t\t\t\t\t&lt;div class=&quot;col-sm-8&quot;&gt;\n\t\t\t\t\t\t\t\t&lt;h3&gt;&lt;?php the_title() ?&gt;&lt;\/h3&gt;\n\t\t\t\t\t\t\t\t&lt;?php the_content(); ?&gt;\n\t\t\t\t\t\t\t&lt;\/div&gt;\n\t\t\t\t\t\t&lt;\/div&gt;\n\t\t        \t&lt;?php \n\t\t\t\t\t\twp_reset_postdata();\n\t\t\t\t\t\tendwhile;\n\t\t\t\t\t\twpbs_pagination();\n\t\t\t\t\t\tendif;\n\t\t\t\t\t?&gt;\n    \t\t\t&lt;\/div&gt;\n    \t\t&lt;\/div&gt;\n    \t&lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/section&gt;\n&lt;?php get_footer(); ?&gt;<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-81343","topic","type-topic","status-closed","hentry","topic-tag-custom-type-post","topic-tag-desenvolvimento-de-tema","topic-tag-taxonomy"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/81343","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":0,"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/81343\/revisions"}],"wp:attachment":[{"href":"https:\/\/br.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=81343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}