Deseja permitir que os usuários filtrem posts e páginas no seu site WordPress? Recentemente, um de nossos usuários nos perguntou como adicionar filtros ao seu site WordPress, permitindo que os usuários filtrem posts por categoria, tags, tipos de post etc. Neste artigo, mostraremos como permitir que os usuários filtrem posts e páginas no WordPress.
Por que permitir que os usuários filtrem posts e páginas no WordPress?
Por padrão, o WordPress vem com categorias e tags para que você possa classificar o conteúdo em tópicos e para que seus usuários possam encontrá-lo facilmente.
No entanto, os usuários só podem visualizar uma categoria, tag ou página de arquivo por vez, e isso mostrará apenas um tipo de post.
E se você quisesse que os usuários pudessem filtrar o conteúdo em mais de uma categoria ou tag? Que tal permitir que os usuários visualizem posts, páginas e tipos de posts personalizados ao mesmo tempo?
Esse tipo de filtragem pode ser particularmente útil quando você tem muito conteúdo e deseja que os usuários o filtrem de acordo com suas próprias preferências.
Dito isso, vamos dar uma olhada em como permitir que os usuários filtrem facilmente posts e páginas no WordPress.
Tutorial em vídeo
Se você não gostar do vídeo ou precisar de mais instruções, continue lendo.
Permitir que os usuários filtrem facilmente publicações e páginas
A primeira coisa que você precisa fazer é instalar e ativar o plug-in Search & Filter. Para obter mais detalhes, consulte nosso guia passo a passo sobre como instalar um plug-in do WordPress.
Após a ativação, o plug-in adicionará um novo item de menu chamado Search & Filter à sua barra de administração do WordPress. Ao clicar nele, você será direcionado para a página de uso do plug-in com documentação detalhada sobre como usar o plug-in.
O plugin Search & Filter vem com um shortcode que aceita diferentes parâmetros para exibir as opções de filtragem. Você pode usar esse shortcode em um post, página ou dentro de um widget de texto.
[searchandfilter fields="search,category,post_tag"]
Você também pode usar o shortcode como uma tag de modelo em seus arquivos de tema do WordPress, como este:
<?php echo do_shortcode('[searchandfilter fields="search,category,post_tag"]'); ?>
Isso exibirá as opções de filtragem com os campos de pesquisa, categoria e tags.
Por padrão, o plug-in aceita pesquisa, taxonomia, post_type e post_date como campos.
Vamos dar uma olhada em outro exemplo. Desta vez, incluiremos os campos category, tags, post types e date.
Você precisará usar o shortcode da seguinte forma:
[searchandfilter fields="search,category,post_tag,post_types,post_date"]
Veja como ficaria:
Agora, em vez de usar o campo de seleção suspenso, você também pode usar caixas de seleção e adicionar rótulos para cada campo. Para fazer isso, você precisará adicionar mais dois parâmetros ao shortcode.
Se você usar uma página separada para exibir as publicações do blog, poderá adicionar esse shortcode à página.
[searchandfilter headings="Select categories:" types="checkbox" fields="category"]
Se estiver usando vários campos, tipos e cabeçalhos, é preciso garantir que os itens estejam na mesma ordem para cada parâmetro.
Vamos ver outro exemplo. Desta vez, estamos adicionando campos de categoria, tags e tipo de post com diferentes cabeçalhos e tipos de campo de formulário.
[searchandfilter headings="Post type, Category, Tag" types="checkbox, select, select" fields="post_types,category,post_tag"]
É assim que isso apareceria em seu site:
Consulte a página de documentação do plug-in para obter mais maneiras de usar o shortcode.
Você também pode usar esses códigos de acesso em um widget de texto. Se o shortcode não funcionar em seu widget de texto, consulte nosso guia sobre como usar shortcodes nos widgets da barra lateral do WordPress.
Esperamos que este artigo tenha ajudado você a aprender como permitir que os usuários filtrem posts e páginas no WordPress. Talvez você também queira ver estas dicas práticas para direcionar o tráfego para seu site WordPress.
Se você gostou deste artigo, inscreva-se em nosso canal do YouTube para receber tutoriais em vídeo sobre o WordPress. Você também pode nos encontrar no Twitter e no Facebook.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Himanshu Gautam says
hi
I am using this plugin
is there any option to select a category without hitting the submit button?
Marwan Nour says
Hello there,
I am trying to implement Search & Filter in a website that’s both in Arabic and in English. The English version of the Search & Filter is working well however in the Arabic Version, after hitting search, I am redirected to the English Version of the search page with the results in English. Can anyone help me with that issue please? Thank you
WPBeginner Support says
You would want to reach out to the plugin’s support to see if this could be a conflict with the plugin and the translation plugin you’re using.
Administrador
Tom Ale says
Hi, I am using WordPress with Gantry.
I installed this plugin and used a shortcode. It appears where it suppose to be. When clicking the button to filter content, nothing happens. Did anyone face this problem? Help, please.
Sébastien Albert says
Hi,
Search & Filter looks great. But could you tell me if it can do that :
I would have a filter on tags but only on one category which I could define…
Thanks a lot
Sebastien
Soumik Sadman Anwar says
How can I create filter options in a single post?
For example, If I am interested in writing a post “Necessary Tools to Build A Website” and want to include filter options like Purpose Based Tools (like SEO, Design etc.) and the Price option (Free or Paid), how do I do it?
Pavel says
Great plugin, but have some limitations and bugs.
1. No Reset button.
2. When I uncheck all checkboxes and press Submit, it transfers to the front page.
Maybe there’s an option Show all?
Wolney Mamede says
First of all, thanks for the post.
I would like to know if it is possible to filter the search from the group of fields, created from the “Advanced Custom Fields – v. 4.4.12” plugin.
Also by default, the search would be restricted to a custom post type from the “Custom Post Type UI – v. 1.5.8” plugin.
Sultan Haider says
Hi, I had created employ database on tablepress and i want to filter in front end employ according to year wise for example if i select 2013 this shows only those employ which join in 2013.
i have perform lot of research but i cant find free pluggin according to my need.
please help me for suggestion.
thanks
Christine says
Thanks a lot for the comprehensive article. Do you know if it is also possible to have only certain tags in the dropdowns?
Pawan says
Great Job. just one last question. Instead of searching the post, is it possible to search category using the search string? I would like to show all the possible post in search page and then the category if it matches the search string (partially or fully).
Maz says
Hi,
Great as always.
I just wonder would the use of this plugin be recommended on a site with many posts? Will it not lead to slower load time?
Thanks
Matus says
Could you please give us a little bit deeper look to your behind the scenes? (in Blueprint post you write only what you’re using – you can also write if you want, how to properly set up plugins, themes…)
For example tutorial on 10 tips and trick to masterize or customize Genesis Framework would be really really helpful.
Patxi says
Hi WPBeginner!
In relation to the filters of new taxonomies, a question of initiation, how I can visualize in the post a new taxonomy for a second type of labels that later I can filter with this plugin?
It would be an interesting topic.
Thanks for you post!
Omer Causey says
Your suggestions for allowing users to filter posts are welcome, but the explanation of how and where to insert the required shortcode is beyond this beginner’s understanding.
WPBeginner Support says
Hi Omer,
You can add the shortcode in a post or page. If you want to display the filter site-wide then you will need to edit your WordPress theme files and use the template tag instead.
Administrador