{"id":9205,"date":"2018-04-25T15:08:03","date_gmt":"2018-04-25T18:08:03","guid":{"rendered":"https:\/\/blog.hostinger.io\/br-tutoriais\/?p=9205"},"modified":"2024-05-23T22:13:26","modified_gmt":"2024-05-24T01:13:26","slug":"como-criar-custom-post-types-wordpress","status":"publish","type":"post","link":"\/br\/tutoriais\/como-criar-custom-post-types-wordpress\/","title":{"rendered":"Custom post types: como criar posts personalizados no WordPress"},"content":{"rendered":"<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Neste tutorial, vamos criar um plugin para adicionar dois novos tipos de post no WordPress, conhecido como <em>Custom Post Type<\/em>. E depois criaremos novos <\/span><i><span style=\"font-weight: 400\">layouts <\/span><\/i><span style=\"font-weight: 400\">para estes novos tipos de posts WordPress usando templates. Voc&ecirc; pode conferir este artigo sobre <\/span><span style=\"font-weight: 400\">como criar plugins WordPress<\/span><span style=\"font-weight: 400\">&nbsp;caso precise refrescar a mem&oacute;ria sobre o assunto.&nbsp;Voc&ecirc; tamb&eacute;m vai aprender como ativar o recurso <\/span><b>Campos Personalizados <\/b><span style=\"font-weight: 400\">para cada post WordPress, e exibir estes campos nos novos templates.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Ao final do artigo de <\/span><b>Como Criar Post Personalizado, <\/b><span style=\"font-weight: 400\">vai notar que o <em>custom post type<\/em>&nbsp;WordPress<\/span> <span style=\"font-weight: 400\">fornecem total controle em como o conte&uacute;do ser&aacute; exibido para os seus visitantes. Se voc&ecirc; escreve posts autorais, voc&ecirc; pode criar um layout somente para eles. Tamb&eacute;m se voc&ecirc; escreve <em>reviews<\/em> de filmes e m&uacute;sicas, voc&ecirc; pode adicionar &aacute;reas para conte&uacute;dos extras e fazer com que estes <em>reviews<\/em> n&atilde;o sejam exibidos como posts do seu blog. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Mas antes de come&ccedil;ar, vamos descobrir o que s&atilde;o <\/span><b>tipos de posts personalizados<\/b><span style=\"font-weight: 400\"> &ndash; <em>Custom Post Type<\/em>&nbsp;WordPress.<\/span><\/p><figure class=\"wp-block-image size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/WordPress-Security-Checklist(pt-br).pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-30402\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2022\/12\/WordPress-Cheat-Sheet-BR.png\/w=1536,fit=scale-down 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-o-que-e-tipo-de-post-personalizado\"><b>O que &Eacute; Tipo de Post Personalizado?<\/b><\/h2><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Em resumo, o tipo de post personalizado WordPress, tradu&ccedil;&atilde;o de <em>Custom Post Types<\/em>, permite que voc&ecirc; classifique seus posts com base no conte&uacute;do de cada um deles. No WordPress, os tipos de post padr&atilde;o s&atilde;o Posts, P&aacute;ginas, Arquivos, etc. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Geralmente, voc&ecirc; escreve todos os seus posts na se&ccedil;&atilde;o <strong>Posts<\/strong> do Painel de Controle do Administrador, e ent&atilde;o seleciona a categoria para cada post. Todos os posts ser&atilde;o exibidos na mesma lista, dificultando assim a diferencia&ccedil;&atilde;o por tipo de conte&uacute;do que cont&eacute;m nos posts.<\/span><\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"900\" height=\"415\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/lista-dos-tipos-de-post-padrao.png\/public\" alt=\"Lista dos tipos de post WordPress padr&atilde;o\" class=\"wp-image-9207\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/lista-dos-tipos-de-post-padrao.png\/w=900,fit=scale-down 900w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/lista-dos-tipos-de-post-padrao.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/lista-dos-tipos-de-post-padrao.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/lista-dos-tipos-de-post-padrao.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n<\/div><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Os tipos de posts personalizados t&ecirc;m seu pr&oacute;prio links no painel de controle do administrador. Os posts criados dessa forma podem ser classificados por categorias, como um post normal, ent&atilde;o voc&ecirc; ter&aacute; total liberdade para classificar e exibir estes posts do jeito que voc&ecirc; quiser. <\/span><\/p><p class=\"wp-block-paragraph\">Vamos deixar claro que, por utilizarmos configura&ccedil;&atilde;o em ingl&ecirc;s, n&oacute;s vamos prosseguir com os <em>prints <\/em>deste tutorial&nbsp;em ingl&ecirc;s, sempre referenciando <em>movies<\/em> para filmes e <em>reviews<\/em> para avalia&ccedil;&otilde;es, ok? Se tiver alguma d&uacute;vida durante o processo, deixe um coment&aacute;rio que vamos te ajudar.<\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">No exemplo acima, se um usu&aacute;rio acessar a se&ccedil;&atilde;o de banco de dados de filmes no seu site, os posts de avalia&ccedil;&otilde;es n&atilde;o estar&atilde;o inclusos. Se voc&ecirc; fizer, por exemplo, as categorias &ldquo;A&ccedil;&atilde;o&rdquo; e &ldquo;Romance&rdquo;, seus usu&aacute;rios podem acessar a p&aacute;gina da categoria &ldquo;A&ccedil;&atilde;o&rdquo; e ler todas as avalia&ccedil;&otilde;es e filmes relacionados a esta categoria. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Quando criar um novo tipo de post, voc&ecirc; tem diversas op&ccedil;&otilde;es como onde o link ser&aacute; exibido no menu do Admin, se os novos tipos de posts est&atilde;o inclusos nos resultados de pesquisa, se aceita cita&ccedil;&otilde;es, se permite coment&aacute;rios, e assim por diante. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Voc&ecirc; pode tamb&eacute;m alterar v&aacute;rias partes do texto (definido usando a <\/span><i><span style=\"font-weight: 400\">array <\/span><\/i><b>$labels<\/b><span style=\"font-weight: 400\">), renomear <\/span><b>Add New Posts <\/b>(adicionar novos posts)<span style=\"font-weight: 400\">&nbsp;para <\/span><b>Add New Movies<\/b> (adicionar novos filmes)<span style=\"font-weight: 400\">. Por exemplo, voc&ecirc; pode renomear o texto &ldquo;<strong>feature image<\/strong><\/span><span style=\"font-weight: 400\">&rdquo; (imagem padr&atilde;o) para&nbsp;<\/span><b>Add Poster <\/b>(adicionar poster)<span style=\"font-weight: 400\">.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Voc&ecirc; tamb&eacute;m pode preferir ativar o recurso de campos personalizados do editor de posts, que est&aacute; oculto por padr&atilde;o e deve ser habilitado usando o link&nbsp;<\/span><b>Screen Options<\/b><span style=\"font-weight: 400\">, na parte superior do editor.<\/span><\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"900\" height=\"854\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/campos-personalizados-post-wordpress.png\/public\" alt=\"Campos personalizados WordPress\" class=\"wp-image-9208\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/campos-personalizados-post-wordpress.png\/w=900,fit=scale-down 900w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/campos-personalizados-post-wordpress.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/campos-personalizados-post-wordpress.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/campos-personalizados-post-wordpress.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n<\/div><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Seguindo com o exemplo dos Movies e Reviews, um post Movies pode adicionar campos personalizados como um <\/span><i><span style=\"font-weight: 400\">release <\/span><\/i><span style=\"font-weight: 400\">anual, diretor, classifica&ccedil;&atilde;o IMDB, e assim por diante, com as sinopses dos filmes sendo o conte&uacute;do dos posts.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Geralmente, qualquer campo personalizado que voc&ecirc; criar poder&aacute; ser selecionado em todos os demais tipos de posts, ent&atilde;o &eacute; preciso um plugin para limitar onde cada um destes campos ser&atilde;o exibidos. <\/span><\/p><h2 class=\"wp-block-heading\" id=\"h-criando-novos-tipos-de-posts\"><b>Criando Novos Tipos de Posts<\/b><\/h2><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Com todas as mudan&ccedil;as significativas do WordPress, <\/span><a href=\"\/br\/tutoriais\/como-criar-um-plugin-um-wordpress\/\"><span style=\"font-weight: 400\">criar um plugin <\/span><\/a><span style=\"font-weight: 400\">&eacute; fortemente recomendado. Voc&ecirc; tamb&eacute;m pode criar um tipo de post personalizado no arquivo <\/span><b>functions.php <\/b><span style=\"font-weight: 400\">de um tema. Neste tutorial, vamos criar um plugin e continuar usando o exemplo do banco de dados\/ <em>reviews,<\/em>&nbsp;ok?<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Para criar um tipo de post personalizado, voc&ecirc; deve escrever uma nova fun&ccedil;&atilde;o que chame a fun&ccedil;&atilde;o WordPress <\/span><b>nomeada register_post_type() <\/b><span style=\"font-weight: 400\">com dois par&acirc;metros. Sua fun&ccedil;&atilde;o <\/span><b>deve <\/b><span style=\"font-weight: 400\">estar conectada &agrave; a&ccedil;&atilde;o gancho <\/span><b>init<\/b><span style=\"font-weight: 400\">, caso contr&aacute;rio, seu tipo de post personalizado n&atilde;o ser&aacute; registrado corretamente.<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ The custom function MUST be hooked to the init action hook\nadd_action( 'init', 'lc_register_movie_post_type' );\n\n\/\/ A custom function that calls register_post_type\nfunction lc_register_movie_post_type() {\n\n  \/\/ Set various pieces of text, $labels is used inside the $args array\n  $labels = array(\n     'name' =&gt; _x( 'Movies', 'post type general name' ),\n     'singular_name' =&gt; _x( 'Movie', 'post type singular name' ),\n     ...\n  );\n\n  \/\/ Set various pieces of information about the post type\n  $args = array(\n    'labels' =&gt; $labels,\n    'description' =&gt; 'My custom post type',\n    'public' =&gt; true,\n    ...\n  );\n\n  \/\/ Register the movie post type with all the information contained in the $arguments array\n  register_post_type( 'movie', $args );\n}<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Todas as fun&ccedil;&otilde;es customizadas devem estar pr&eacute;-fixadas para evitar conflitos quando usar outros plugins ou outras fun&ccedil;&otilde;es do tema. Aqui vamos usar aleatoriamente as letras LC, apenas como exemplo. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Os dois par&acirc;metros para <\/span><b>register_post_type()<\/b><span style=\"font-weight: 400\"> s&atilde;o:<\/span><\/p><ol class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">O nome do tipo de post, m&aacute;ximo de 20 caracteres e n&atilde;o pode conter espa&ccedil;os ou letras mai&uacute;sculas.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Uma <\/span><b><em>array<\/em> <\/b><span style=\"font-weight: 400\">associativa nomeada <\/span><b>$args<\/b><span style=\"font-weight: 400\"> que cont&eacute;m informa&ccedil;&otilde;es chaves sobre os tipos de post em pares <\/span><b>&lsquo;key&rsquo; =&gt; &lsquo;value&rsquo;<\/b><span style=\"font-weight: 400\">. <\/span><\/li>\n<\/ol><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Como os argumentos e a <\/span><i><span style=\"font-weight: 400\">label<\/span><\/i><span style=\"font-weight: 400\"> s&atilde;o <\/span><i><span style=\"font-weight: 400\">arrays<\/span><\/i><span style=\"font-weight: 400\">, &eacute; mais claro escrever primeiro a <\/span><i><span style=\"font-weight: 400\">label<\/span><\/i><span style=\"font-weight: 400\"> em sua pr&oacute;pria vari&aacute;vel, depois a vari&aacute;vel $args, e s&oacute; ent&atilde;o chamar a fun&ccedil;&atilde;o. <\/span><\/p><h3 class=\"wp-block-heading\" id=\"h-o-args-array\"><b>O $args <em>Array<\/em><\/b><\/h3><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">As chaves mais usadas para o <\/span><i><span style=\"font-weight: 400\">array <\/span><\/i><b>$args <\/b><span style=\"font-weight: 400\">est&atilde;o listadas abaixo, e s&atilde;o todas opcionais: <\/span><\/p><ul class=\"wp-block-list\">\n<li><b>labels<\/b><span style=\"font-weight: 400\"> &ndash; um <\/span><em><b>array<\/b><\/em><span style=\"font-weight: 400\"> que define v&aacute;rias partes do texto, por exemplo &ldquo;Add new post&rdquo; pode ser renomeado para &ldquo;Add new movie&rdquo;. As <\/span><i><span style=\"font-weight: 400\">keys <\/span><\/i><span style=\"font-weight: 400\">para os <\/span><i><span style=\"font-weight: 400\">labels array<\/span><\/i><span style=\"font-weight: 400\"> ser&atilde;o explicados na lista abaixo.<\/span><\/li>\n\n\n\n<li><b>description<\/b><span style=\"font-weight: 400\">&ndash; um curto e descritivo sum&aacute;rio do tipo de post, isto pode ser exibido nos templates dos tipos de posts mas n&atilde;o &nbsp;aparecer&aacute; em nenhum outro lugar.<\/span><\/li>\n\n\n\n<li><b>public <span style=\"font-weight: 400\">&ndash; se os tipos de posts est&atilde;o vis&iacute;veis para autores e visitantes, o valor padr&atilde;o &eacute; FALSE, e significa que n&atilde;o aparecer&aacute; no Painel de Controle do Administrador. <\/span><\/b><\/li>\n\n\n\n<li><b>exclude_from_search <\/b><span style=\"font-weight: 400\">&ndash; se os posts deste tipos aparecem normalmente nos resultados de pesquisa. O valor padr&atilde;o &eacute; o oposto do valor do p&uacute;blico.<\/span><\/li>\n\n\n\n<li><b>publicly_queryable <span style=\"font-weight: 400\">&ndash; se os posts deste tipo podem ser recuperadas usando a URL, como <strong>http:\/\/www.mywebsite.com\/?post_type=movie<\/strong>, ou no modo avan&ccedil;ado via fun&ccedil;&atilde;o query_posts(). O valor padr&atilde;o &eacute; o valor p&uacute;blico.<\/span><\/b><\/li>\n\n\n\n<li><strong>show_ui<\/strong> <span style=\"font-weight: 400\">&ndash; se o menu de links e o editor de posts ser&atilde;o vis&iacute;veis no Painel de Controle do Administrador. O valor padr&atilde;o &eacute; o valor p&uacute;blico.<\/span><\/li>\n\n\n\n<li><strong>show_in_nav_menus<\/strong> <span style=\"font-weight: 400\">&ndash; se os posts deste tipo podem ser adicionados para navega&ccedil;&atilde;o nos menus criados via tela Apar&ecirc;ncia &gt; Menus. O valor padr&atilde;o &eacute; o valor p&uacute;blico.<\/span><\/li>\n\n\n\n<li><b>show_in_menu<\/b><span style=\"font-weight: 400\"> &ndash; onde o link dos tipos de posts v&atilde;o aparecer na navega&ccedil;&atilde;o no painel de controle do administrador. FALSE oculta o link. TRUE adiciona o link como um novo link de n&iacute;vel superior. Digitar uma <\/span><i><span style=\"font-weight: 400\">string <\/span><\/i><span style=\"font-weight: 400\">permite colocar o link como sublink existente ao link de n&iacute;vel superior, ou seja, digitando <\/span><b>options-general.php<\/b><span style=\"font-weight: 400\">, ser&aacute; aplicado abaixo do link Configura&ccedil;&otilde;es<\/span><b>. <\/b><\/li>\n\n\n\n<li><b>Show_in_admin_bar <span style=\"font-weight: 400\">&ndash; se o tipo de posts aparecer&aacute; na barra superior do Admin, abaixo do link +novo.<\/span><\/b><\/li>\n\n\n\n<li><b>Menu_position &ndash; <\/b><span style=\"font-weight: 400\">posi&ccedil;&atilde;o do novo link na navega&ccedil;&atilde;o do Painel de Controle do Administrador, 5 coloca-o abaixo dos posts, 100 coloca-o abaixo de Configura&ccedil;&otilde;es, visite a entrada WordPress Codex para a lista completa de posi&ccedil;&otilde;es.<\/span><\/li>\n\n\n\n<li><b>Hierarchical <\/b><span style=\"font-weight: 400\">&ndash; se os posts podem ser atribu&iacute;dos a um post Parent, se for TRUE, o <\/span><i><span style=\"font-weight: 400\">array <\/span><\/i><span style=\"font-weight: 400\">$support deve conter o recurso &lsquo;page-attributes&rsquo;.<\/span><\/li>\n\n\n\n<li><b>supports<\/b><span style=\"font-weight: 400\"> &ndash; habilita de forma seletiva v&aacute;rios recursos de posts, como imagens em destaque, cita&ccedil;&otilde;es, campos personalizados, etc. Se definida como FALSE ao inv&eacute;s de <\/span><i><span style=\"font-weight: 400\">array<\/span><\/i><span style=\"font-weight: 400\">, desabilitar&aacute; o editor para este tipo de post &ndash; isto &eacute; muito &uacute;til se voc&ecirc; quer bloquear todos os posts deste tipo enquanto os mant&eacute;m vis&iacute;veis (lista dos valores <\/span><i><span style=\"font-weight: 400\">arrays, <\/span><\/i><span style=\"font-weight: 400\">est&atilde;o logo abaixo). <\/span><\/li>\n\n\n\n<li><b>Taxonomies <\/b><span style=\"font-weight: 400\">&ndash; um <\/span><i><span style=\"font-weight: 400\">array <\/span><\/i><span style=\"font-weight: 400\">de taxonomias que podem ser aplicadas a posts deste tipo, taxonomias devem j&aacute; estar registradas &ndash; isto n&atilde;o as cria.<\/span><\/li>\n\n\n\n<li><b>Has_archive <span style=\"font-weight: 400\">&ndash;<\/span> <span style=\"font-weight: 400\">se o tipo de post tem uma p&aacute;gina de arquivo, a url segue a estrutura do permalink, e o <\/span><i><span style=\"font-weight: 400\">slug<\/span><\/i><span style=\"font-weight: 400\"> &eacute; o nome que voc&ecirc; insere no par&acirc;metro 1 do register_post_types(), ou seja, http:\/\/www.mysite.com\/movies_reviews\/ mostra todos posts movies_reviews.<\/span><\/b><\/li>\n\n\n\n<li><b>query_var<\/b><span style=\"font-weight: 400\"> &nbsp;&ndash; TRUE ou FALSE define se o post pode ser visualizado ao inserir o tipo de post e o nome do post ao consultar a url, ou seja, &lsquo;http:\/\/www.mysite.com\/?<\/span><b>movie<\/b><span style=\"font-weight: 400\">=<\/span><b>matrix<\/b><span style=\"font-weight: 400\">&lsquo;. Se voc&ecirc; digitar uma <em>string<\/em> de texto, voc&ecirc; pode configurar o texto para ser usado depois do caractere <\/span><b>?<\/b><span style=\"font-weight: 400\">, ent&atilde;o ao digitar &lsquo;filme&rsquo; resultaria em &lsquo;?<\/span><b>filme=matrix&rsquo;<\/b><span style=\"font-weight: 400\">.<\/span><\/li>\n<\/ul><p class=\"wp-block-paragraph\">Esta lista completa pode ser visualizada no <a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/register_post_type#Arguments\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress Codex page for register_post_type()<\/a>.<\/p><h3 class=\"wp-block-heading\" id=\"h-os-labels-array\"><b>Os <\/b><b><i>labels Array<\/i><\/b><\/h3><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">A primeira <\/span><b>key<\/b><span style=\"font-weight: 400\"> no <\/span><i><span style=\"font-weight: 400\">array <\/span><\/i><b>$arg<\/b> <span style=\"font-weight: 400\">&eacute; nomeada <\/span><b>labels <\/b><span style=\"font-weight: 400\">e deve ser um <\/span><i><span style=\"font-weight: 400\">array<\/span><\/i><span style=\"font-weight: 400\">. Isto define v&aacute;rias partes do texto relacionado a este post. Como isto cont&eacute;m muitas informa&ccedil;&otilde;es, &eacute; melhor criar uma vari&aacute;vel chamada <\/span><b>$labels <\/b><span style=\"font-weight: 400\">para armazen&aacute;-la. O c&oacute;digo de exemplo acima deixa isso bem claro. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Abaixo est&atilde;o algumas importantes <\/span><b>keys <\/b><span style=\"font-weight: 400\">para os labels <em>arrays<\/em>, todos s&atilde;o opcionais. <\/span><\/p><ul class=\"wp-block-list\">\n<li><b>name<\/b><span style=\"font-weight: 400\"> &ndash; o nome geral para o tipo de post, por exemplo: movies.<\/span><\/li>\n\n\n\n<li><b>singular_name<\/b><span style=\"font-weight: 400\"> &ndash; Nome para um post singular deste tipo, por exemplo: movies.<\/span><\/li>\n\n\n\n<li><b>add_new<\/b><span style=\"font-weight: 400\"> &ndash; substitui o texto &lsquo;Add New&rsquo; por &lsquo;Add Movie&rsquo;, por exemplo.<\/span><\/li>\n\n\n\n<li><b>add_new_item <\/b><span style=\"font-weight: 400\">&ndash; substitui o texto &lsquo;Add New Post&rsquo; por &lsquo;Add New Movie&rsquo;<\/span><\/li>\n\n\n\n<li><b>edit_item<\/b><span style=\"font-weight: 400\"> &ndash; Substitui &lsquo;Edit Post&rsquo; por &lsquo;Edit Movie&rsquo;.<\/span><\/li>\n\n\n\n<li><b>featured_image<\/b><span style=\"font-weight: 400\"> &ndash; Substitui &lsquo;Feature Image&rsquo; no editor por &lsquo;Movie Post&rsquo;<\/span><\/li>\n\n\n\n<li><b>set_featured_image<\/b><span style=\"font-weight: 400\"> &ndash; &nbsp;Substitui &lsquo;Define Feature Image&rsquo; por &lsquo;Add Poster Movie&rsquo;, por exemplo.<\/span><\/li>\n\n\n\n<li><b>menu_name<\/b><span style=\"font-weight: 400\"> &ndash; Altera o texto do link de n&iacute;vel superior, o padr&atilde;o do texto e o nome da key. <\/span><\/li>\n<\/ul><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Consulte a lista completa no <\/span><a href=\"https:\/\/codex.wordpress.org\/Function_Reference\/register_post_type#Arguments\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"font-weight: 400\">WordPress Codex page for register_post_type()<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p><h3 class=\"wp-block-heading\" id=\"h-os-supports-array\"><b>Os &lsquo;supports&rsquo; <em>Array<\/em><\/b><\/h3><pre class=\"wp-block-preformatted\">\/\/ Enable specific features in the post editor for my post type\n$supports = array ( 'title', 'editor', 'author', 'thumbnail' );\n\n\/\/ Disable ALL features of the post editor for my post type\n$supports = FALSE;<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Uma das keys no <em>array<\/em> <\/span><b>$args <\/b><span style=\"font-weight: 400\">&eacute; nomeada <\/span><b>supports<\/b><span style=\"font-weight: 400\">. Esta &eacute; uma <em>array<\/em> simples onde voc&ecirc; escreve a lista de recursos do editor de posts personalizados. Por padr&atilde;o, somente o t&iacute;tulo e o editor s&atilde;o habilitados. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Voc&ecirc; tamb&eacute;m pode escrever FALSE ao inv&eacute;s de uma <em>array<\/em>, para desabilitar todos os recursos de edi&ccedil;&atilde;o dos posts, incluindo t&iacute;tulo e conte&uacute;do. Isto significa que os posts n&atilde;o poder&atilde;o ser editados, mas continuam completamente vis&iacute;veis. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Aqui est&aacute; uma lista de recursos dos editores de post que voc&ecirc; pode habilitar na <em>array<\/em> <\/span><b>$supports<\/b><span style=\"font-weight: 400\">: <\/span><\/p><ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Title (t&iacute;tulo);<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Editor;<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Author &ndash; (Autor) NOTA: este recurso permite alterar o autor do post;<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Thumbnail (miniatura);<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Excerpt (resumo);<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">trackbacks;<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Custom-fields (campos personalizados);<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Comments (coment&aacute;rios);<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Revisions (revis&otilde;es);<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Page-attributes (atributos da p&aacute;gina);<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Post-formats (formato dos posts).<\/span><\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-criar-novos-tipos-de-post-via-plugin\"><b>Criar Novos Tipos de Post via Plugin <\/b><\/h2><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Agora que sabemos quais informa&ccedil;&otilde;es s&atilde;o necess&aacute;rias para uma fun&ccedil;&atilde;o, podemos criar nosso pr&oacute;prio plugin, gravar fun&ccedil;&otilde;es personalizadas, e conect&aacute;-las ao gancho <\/span><b>init<\/b><span style=\"font-weight: 400\">.<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/*\nPlugin Name: My Custom Post Types\nDescription: Add post types for movies and movie reviews\nAuthor: Liam Carberry\n*\/\n \n\/\/ Hook &lt;strong&gt;lc_custom_post_movie()&lt;\/strong&gt; to the init action hook\nadd_action( 'init', 'lc_custom_post_movie' );\n \n\/\/ The custom function to register a movie post type\nfunction lc_custom_post_movie() {\n \n  \/\/ Set the labels, this variable is used in the $args array\n  $labels = array(\n    'name'               =&gt; __( 'Movies' ),\n    'singular_name'      =&gt; __( 'Movie' ),\n    'add_new'            =&gt; __( 'Add New Movie' ),\n    'add_new_item'       =&gt; __( 'Add New Movie' ),\n    'edit_item'          =&gt; __( 'Edit Movie' ),\n    'new_item'           =&gt; __( 'New Movie' ),\n    'all_items'          =&gt; __( 'All Movies' ),\n    'view_item'          =&gt; __( 'View Movie' ),\n    'search_items'       =&gt; __( 'Search Movies' ),\n    'featured_image'     =&gt; 'Poster',\n    'set_featured_image' =&gt; 'Add Poster'\n  );\n \n  \/\/ The arguments for our post type, to be entered as parameter 2 of register_post_type()\n  $args = array(\n    'labels'            =&gt; $labels,\n    'description'       =&gt; 'Holds our movies and movie specific data',\n    'public'            =&gt; true,\n    'menu_position'     =&gt; 5,\n    'supports'          =&gt; array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),\n    'has_archive'       =&gt; true,\n    'show_in_admin_bar' =&gt; true,\n    'show_in_nav_menus' =&gt; true,\n    'has_archive'       =&gt; true,\n    'query_var'         =&gt; 'film'\n  );\n \n  \/\/ Call the actual WordPress function\n  \/\/ Parameter 1 is a name for the post type\n  \/\/ Parameter 2 is the $args array\n  register_post_type( 'movie', $args);\n}\n \n\/\/ Hook &lt;strong&gt;lc_custom_post_movie_reviews()&lt;\/strong&gt; to the init action hook\nadd_action( 'init', 'lc_custom_post_movie_reviews' );\n \n\/\/ The custom function to register a movie review post type\nfunction lc_custom_post_movie_reviews() {\n \n  \/\/ Set the labels, this variable is used in the $args array\n  $labels = array(\n    'name'               =&gt; __( 'Movie Reviews' ),\n    'singular_name'      =&gt; __( 'Movie Review' ),\n    'add_new'            =&gt; __( 'Add New Movie Review' ),\n    'add_new_item'       =&gt; __( 'Add New Movie Review' ),\n    'edit_item'          =&gt; __( 'Edit Movie Review' ),\n    'new_item'           =&gt; __( 'New Movie Review' ),\n    'all_items'          =&gt; __( 'All Movie Reviews' ),\n    'view_item'          =&gt; __( 'View Movie Reviews' ),\n    'search_items'       =&gt; __( 'Search Movie Reviews' )\n  );\n \n  \/\/ The arguments for our post type, to be entered as parameter 2 of register_post_type()\n  $args = array(\n    'labels'            =&gt; $labels,\n    'description'       =&gt; 'Holds our movie reviews',\n    'public'            =&gt; true,\n    'menu_position'     =&gt; 6,\n    'supports'          =&gt; array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),\n    'has_archive'       =&gt; true,\n    'show_in_admin_bar' =&gt; true,\n    'show_in_nav_menus' =&gt; true,\n    'has_archive'       =&gt; true\n  );\n \n  \/\/ Call the actual WordPress function\n  \/\/ Parameter 1 is a name for the post type\n  \/\/ $args array goes in parameter 2.\n  register_post_type( 'review', $args);\n}<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Se voc&ecirc; habilitar este plugin, voc&ecirc; agora deve ver dois novos links na navega&ccedil;&atilde;o do Painel de Controle do Administrador, logo abaixo o link Posts. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Ao passar o mouse sobre os sublinks, voc&ecirc; vai ver &ldquo;View all&rdquo; e &ldquo;Add new&rdquo;, o texto ser&aacute; definido na <em>array<\/em> <\/span><b>$labels<\/b><span style=\"font-weight: 400\">. Confira o seu editor e veja que as labels mudaram.<\/span><\/p><h2 class=\"wp-block-heading\" id=\"h-limitando-campos-personalizados-ao-tipo-de-post-especifico\"><b>Limitando Campos Personalizados ao Tipo de Post Espec&iacute;fico<\/b><\/h2><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Quando adicionar um campo personalizado a um post, este campo j&aacute; permanece salvo e ent&atilde;o voc&ecirc; pode rapidamente adicion&aacute;-lo a qualquer post. Os campos personalizados que voc&ecirc; adicionar, aparecer&atilde;o em uma lista suspensa em cada post.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Isto pode dificultar a localiza&ccedil;&atilde;o dos campos que voc&ecirc; precisa em tipos de posts espec&iacute;ficos. Se voc&ecirc; quer limitar os campos personalizados para que estejam dispon&iacute;veis somente em determinados tipos de posts, o jeito mais f&aacute;cil &eacute; usar um plugin.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">O <\/span><a href=\"https:\/\/wordpress.org\/plugins\/advanced-custom-fields\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"font-weight: 400\">plugin avan&ccedil;ado de campos personalizados<\/span><\/a><span style=\"font-weight: 400\"> adiciona um simples editor ao WordPress que permite criar campos personalizados e definir que sejam exibidos somente no seus tipos de post.<\/span><\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"900\" height=\"270\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/menu-suspenso-do-tipo-de-post.png\/public\" alt=\"Menu suspenso dos tipos de post, passo necess&aacute;rio para criar custom post type\" class=\"wp-image-9210\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/menu-suspenso-do-tipo-de-post.png\/w=900,fit=scale-down 900w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/menu-suspenso-do-tipo-de-post.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/menu-suspenso-do-tipo-de-post.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2018\/04\/menu-suspenso-do-tipo-de-post.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n<\/div><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Voc&ecirc; pode definir qual tipo de entrada cada campo dever&aacute; ter, como por exemplo caixa de texto, &aacute;rea de texto, endere&ccedil;o de email, etc., ou algo mais avan&ccedil;ado como embedar o Google Maps, com o qual voc&ecirc; pode selecionar uma localiza&ccedil;&atilde;o para destacar e exibir nos seus posts.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Voc&ecirc; tamb&eacute;m pode definir onde, na tela do editor, os campos personalizados ser&atilde;o exibidos. Como estes campos s&atilde;o criados via plugin, voc&ecirc; deve usar a fun&ccedil;&atilde;o desse plugin para exibi-las. Isto ser&aacute; explicado na pr&oacute;xima se&ccedil;&atilde;o. <\/span><\/p><h2 class=\"wp-block-heading\" id=\"h-estilizando-novos-tipos-de-posts\"><b>Estilizando Novos Tipos de Posts <\/b><\/h2><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Para criar temas de templates para seus tipos de posts, voc&ecirc; precisa somente tem que criar arquivos dentro do diret&oacute;rio principal do seu tema com os nomes corretos. Se voc&ecirc; n&atilde;o criar templates, o WordPress usar&aacute; <\/span><b>single.php<\/b><span style=\"font-weight: 400\"> e <\/span><b>archive.php <\/b><span style=\"font-weight: 400\">no lugar, mantendo todos os seus posts e arquivos id&ecirc;nticos. <\/span><\/p><ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Template para um post individual &nbsp;&ndash; <\/span><b>single-{post-type}.php<\/b><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Template para uma p&aacute;gina de arquivo &ndash; <\/span><b>archive-{post-type}.php<\/b><span style=\"font-weight: 400\">.<\/span><\/li>\n<\/ul><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">A parte <\/span><b>{post-type} <\/b><span style=\"font-weight: 400\">dos nomes dos arquivos deve ser o nome do par&acirc;metro 1 do <\/span><b>register_post_type()<\/b><span style=\"font-weight: 400\">.<\/span><\/p><ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Para o nosso tipo de post Movie, os nomes dos arquivos s&atilde;o <\/span><b>single-movie.php<\/b><span style=\"font-weight: 400\"> and <\/span><b>archive-movie.php<\/b><span style=\"font-weight: 400\">.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">Para nosso tipo de post Review, os nomes dos arquivos s&atilde;o <\/span><b>single-review.php<\/b><span style=\"font-weight: 400\"> e <\/span><b>archive-review.php<\/b><span style=\"font-weight: 400\">.<\/span><\/li>\n<\/ul><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">O melhor caminho para come&ccedil;ar, &eacute; duplicando <\/span><b>single.php <\/b><span style=\"font-weight: 400\">ou <\/span><b>archive.php <\/b><span style=\"font-weight: 400\">e renome&aacute;-los como acima. Isto significa que no geral, a estrutura &eacute; id&ecirc;ntica ao restante do tema, e todos as tags dos templates necess&aacute;rias j&aacute; est&atilde;o no devido lugar. <\/span><\/p><h2 class=\"wp-block-heading\" id=\"h-exibindo-campos-personalizados-nos-posts\"><b>Exibindo Campos Personalizados nos Posts <\/b><\/h2><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Para exibir campos personalizados criados no editor padr&atilde;o do WordPress, voc&ecirc; pode usar duas fun&ccedil;&otilde;es.<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Generates all custom fields attached to the post in a &lt;ul&gt; list\nthe_meta();\n\n\/\/ Get a specific piece of information\necho get_post_meta( $post-&gt;ID, 'Budget', TRUE );<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\"> Estas fun&ccedil;&otilde;es devem estar nos arquivos dos templates &nbsp;usados para exibir os seus posts. <\/span><\/p><h4 class=\"wp-block-heading\" id=\"h-the-meta\"><b>the_meta()<\/b><\/h4><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Exibe todos os campos personalizados anexados ao post na lista &lt;ul&gt;.&nbsp;A tag final &lt;ul&gt; se parecer&aacute; com isto:<\/span><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;ul class='post-meta'&gt;\n  &lt;li&gt;\n    &lt;span class='post-meta-key'&gt;{your_key}&lt;\/span&gt; {your_value}\n  &lt;\/li&gt;\n&lt;\/ul&gt;<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Isto funciona em qualquer lugar de um template de post de individual, mas se voc&ecirc; est&aacute; exibindo em algum outro lugar, dever&aacute; ser inserida no WordPress loop.<\/span><\/p><h4 class=\"wp-block-heading\" id=\"h-get-post-meta\"><b>get_post_meta()<\/b><\/h4><ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">Usa 3 par&acirc;metros e retorna um resultado.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">O primeiro par&acirc;metro &eacute; o ID do post, voc&ecirc; pode usar aqui o <\/span><b>$post-&gt;ID<\/b><span style=\"font-weight: 400\"> para conseguir a ID do post atual.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">O segundo par&acirc;metro &eacute; o nome do campo personalizado, e &eacute; <\/span><i><span style=\"font-weight: 400\">case-sensitive<\/span><\/i><span style=\"font-weight: 400\">. <\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">O terceiro par&acirc;metro &eacute; um <\/span><i><span style=\"font-weight: 400\">boolean <\/span><\/i><span style=\"font-weight: 400\">nomeado <\/span><b>$single<\/b><span style=\"font-weight: 400\"> e pode ser &nbsp;TRUE (retorna o resultado como uma string) ou FALSE (retorna uma <em>array<\/em>).<\/span><\/li>\n<\/ul><p>\n\n\n<div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <b>NOTA: <\/b>Voc&ecirc; pode criar m&uacute;ltiplos campos personalizados com o mesmo nome e diferentes valores. Se existir m&uacute;ltiplos campos com o mesmo nome, configurando FALSE retornar&aacute; uma <em>array<\/em> de todos eles.\n            <\/p><\/div>\n\n\n\n<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n  $movie_box_art = get_post_meta( $post-&gt;ID, 'Box Art', TRUE );\n\nif (!empty($movie_box_art)) { ?&gt;\n  &lt;div class=\"movie-poster-box\"&gt;\n    &lt;img src=\"&lt;?php echo $movie_poster ?&gt;\" alt=\"&lt;?php single_post_title(); ?&gt; \"&gt;\n  &lt;\/div&gt;\n&lt;? } ?&gt;<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Como a fun&ccedil;&atilde;o <\/span><b>get_post_meta()<\/b><span style=\"font-weight: 400\"> retorna um valor, voc&ecirc; pode usar o valor em uma instru&ccedil;&atilde;o condicional para alterar o layout apropriadamente.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">No exemplo acima, n&oacute;s verificamos se &lsquo;movie&rsquo; tem uma caixa de arte atribu&iacute;da a ele via um campo personalizado. Se <\/span><b>$movie_box_art<\/b><span style=\"font-weight: 400\"> n&atilde;o est&aacute; vazio, copie o <em>div<\/em> e a imagem.<\/span><\/p><h3 class=\"wp-block-heading\" id=\"h-exibindo-campos-personalizados-avancados\">Exibindo <a href=\"https:\/\/wordpress.org\/plugins\/advanced-custom-fields\/\" target=\"_blank\" rel=\"noopener\">Campos Personalizados Avan&ccedil;ados<\/a><\/h3><pre class=\"wp-block-preformatted\">\/\/ Display field value\nthe_field( 'FIELD NAME' );\n\n\/\/ Return field value\nget_field( 'FIELD NAME' );<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Os plugins de campos personalizados avan&ccedil;ados fornecem sua pr&oacute;pria fun&ccedil;&atilde;o e <\/span><i><span style=\"font-weight: 400\">shortcodes <\/span><\/i><span style=\"font-weight: 400\">para exibir os campos. <\/span><\/p><h4 class=\"wp-block-heading\" id=\"h-the-field-nbsp-field-name-nbsp\"><b>the_field( &nbsp;&lsquo; FIELD NAME&rsquo; &nbsp;);<\/b><\/h4><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Exibe o valor do campo espec&iacute;fico, e voc&ecirc; deve usar o Nome do Campo que inseriu quando criou o grupo de Campos. <\/span><\/p><h4 class=\"wp-block-heading\" id=\"h-get-field-field-name\"><b>get_field( &lsquo;FIELD NAME&rsquo; );<\/b><\/h4><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Retorna o valor do campo espec&iacute;fico, &uacute;til para instru&ccedil;&otilde;es condicionais. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Estas s&atilde;o as fun&ccedil;&otilde;es que voc&ecirc; deve usar com mais frequ&ecirc;ncia. Mas existem fun&ccedil;&otilde;es mais avan&ccedil;adas e voc&ecirc; pode consult&aacute;-las no <\/span><a href=\"https:\/\/www.advancedcustomfields.com\/resources\/#functions\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"font-weight: 400\">Documento Oficial<\/span><\/a><span style=\"font-weight: 400\">.<\/span><\/p><h4 class=\"wp-block-heading\" id=\"h-shortcode\"><b>Shortcode<\/b><\/h4><pre class=\"wp-block-preformatted\">\n<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Voc&ecirc; pode exibir os campos diretamente em um post usando o <em>shortcode<\/em> acima.<\/span><\/p><h2 class=\"wp-block-heading\" id=\"h-exibindo-tipos-de-posts-personalizados-na-pagina-inicial\"><b>Exibindo Tipos de Posts Personalizados na P&aacute;gina Inicial<\/b><\/h2><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/ Hook our custom function to the pre_get_posts action hook\nadd_action( 'pre_get_posts', 'add_reviews_to_frontpage' );\n \n\/\/ Alter the main query\nfunction add_reviews_to_frontpage( $query ) {\n    if ( is_home() &amp;&amp; $query-&gt;is_main_query() ) {\n        $query-&gt;set( 'post_type', array( 'post', 'movie', 'review' ) );\n    }\n    return $query;\n}\n<\/pre><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Por padr&atilde;o, os tipos de posts personalizados n&atilde;o s&atilde;o exibidos na p&aacute;gina inicial, ent&atilde;o voc&ecirc; tem que gravar uma nova fun&ccedil;&atilde;o que chame o m&eacute;todo <\/span><b>set <\/b><span style=\"font-weight: 400\">do WordPress&rsquo; <\/span><b>WP_Query<\/b><span style=\"font-weight: 400\">.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">A fun&ccedil;&atilde;o verifica se o visitante est&aacute; na p&aacute;gina inical e se a <\/span><i><span style=\"font-weight: 400\">query <\/span><\/i><span style=\"font-weight: 400\">ativa &eacute; a principal gerada pelo WordPress. <\/span><\/p><p class=\"wp-block-paragraph\"><b>$query-&gt;set() <\/b><span style=\"font-weight: 400\">usa dois par&acirc;metros:<\/span><\/p><ul class=\"wp-block-list\">\n<li><span style=\"font-weight: 400\">O primeiro par&acirc;metro &eacute; a propriedade que voc&ecirc; quer alterar, neste caso pretendemos querer alterar a propriedade <\/span><b>post_type<\/b><span style=\"font-weight: 400\">.<\/span><\/li>\n\n\n\n<li><span style=\"font-weight: 400\">O segundo par&acirc;metro &eacute; a <em>array<\/em> que voc&ecirc; quer como valor da propriedade <\/span><b>post_type.<\/b><\/li>\n<\/ul><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">No c&oacute;digo acima, o <em>array<\/em> come&ccedil;a com &lsquo;post&rsquo; &ndash; isto acontece porque cada post no WordPress tem um tipo de post &lsquo;post&rsquo;, e n&oacute;s queremos inclu&iacute;-los na p&aacute;gina inicial.<\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Se voc&ecirc; quer personalizar os posts de um determinado tipo na p&aacute;gina inicial, voc&ecirc; pode remover o tipo &lsquo;posts&rsquo; e aplicar somente o seu tipo de post personalizado. N&oacute;s adicionamos &lsquo;movie&rsquo; e &lsquo;review&rsquo; na <em>array<\/em>, ent&atilde;o a p&aacute;gina inicial agora exibe posts regulares, todos os posts de filmes e todos os posts de avalia&ccedil;&otilde;es. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">O valor que voc&ecirc; inserir deve ser o nome usado no par&acirc;metro 1 da fun&ccedil;&atilde;o <\/span><b>register_post_type()<\/b><span style=\"font-weight: 400\">.<\/span><\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"\/br\/hospedagem-wordpress\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/public\" alt=\"\" class=\"wp-image-44638\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/53\/2024\/06\/BR-New-WP_in-text-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div><h2 class=\"wp-block-heading\" id=\"h-conclusao\"><b>Conclus&atilde;o<\/b><\/h2><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Neste tutorial voc&ecirc; aprendeu como criar tipos de posts personalizados&nbsp;<em>(<\/em><em>custom post types)<\/em>, e as informa&ccedil;&otilde;es que voc&ecirc; precisa para fazer isso. A flexibilidade que um tipo de post personalizado fornece faz disso um recurso essencial para qualquer site desenvolvido no WordPress. <\/span><\/p><p class=\"wp-block-paragraph\"><span style=\"font-weight: 400\">Quando alinhado com categorias e taxonomias, voc&ecirc; tem controle total de como os seus usu&aacute;rios visualizam os seus posts.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Neste tutorial, vamos criar um plugin para adicionar dois novos tipos de post no WordPress, conhecido como Custom Post Type. E depois criaremos novos layouts para estes novos tipos de posts WordPress usando templates. Voc&ecirc; pode conferir este artigo sobre como criar plugins WordPress&nbsp;caso precise refrescar a mem&oacute;ria sobre o assunto.&nbsp;Voc&ecirc; tamb&eacute;m vai aprender como [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/br\/tutoriais\/como-criar-custom-post-types-wordpress\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":78,"featured_media":38593,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"rank_math_title":"Custom Post Type: Como Criar Posts Personalizados no WordPress","rank_math_description":"Tenha mais autonomia no seu blog WordPress! Veja como criar tipos de posts personalizados (Custom Post Type) e tenha total controle.","rank_math_focus_keyword":"custom post type","footnotes":""},"categories":[4911],"tags":[5439,5440],"class_list":["post-9205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-custom-post-types","tag-tipos-de-posts-personalizados"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-criar-custom-post-types-wordpress\/","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/comment-creer-custom-post-type-wordpress\/","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/custom-post-types-wordpress\/","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-membuat-custom-post-types\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/wordpress-custom-post-types\/","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/custom-post-types-wordpress\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/custom-post-types-wordpress\/","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/custom-post-types-wordpress\/","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-criar-custom-post-types-wordpress\/","default":0}],"acf":[],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/9205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/comments?post=9205"}],"version-history":[{"count":15,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/9205\/revisions"}],"predecessor-version":[{"id":44065,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/posts\/9205\/revisions\/44065"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/media\/38593"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/media?parent=9205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/categories?post=9205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/br\/tutoriais\/wp-json\/wp\/v2\/tags?post=9205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}