Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coppa WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Come consentire agli utenti di filtrare i post e le pagine in WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Volete consentire agli utenti di filtrare i post e le pagine del vostro sito WordPress? Recentemente, uno dei nostri utenti ci ha chiesto come aggiungere filtri al proprio sito WordPress, consentendo agli utenti di filtrare i post per categoria, tag, tipi di post, ecc. In questo articolo vi mostreremo come permettere agli utenti di filtrare i post e le pagine in WordPress.

How to Let Users Filter Posts and Pages in WordPress

Perché permettere agli utenti di filtrare i post e le pagine in WordPress?

Per impostazione predefinita, WordPress è dotato di categorie e tag come modo per ordinare i contenuti in argomenti e per consentire agli utenti di trovarli facilmente.

Tuttavia, gli utenti possono visualizzare una sola categoria, un solo tag o una sola pagina di archivio alla volta, e mostreranno solo un tipo di post.

E se voleste che gli utenti potessero filtrare i contenuti di più di una categoria o di un tag? E se si volesse permettere agli utenti di visualizzare contemporaneamente post, pagine e tipi di post personalizzati?

Questo tipo di filtraggio può essere particolarmente utile quando si hanno molti contenuti e si vuole che gli utenti li filtrino in base alle loro preferenze.

Detto questo, vediamo come permettere agli utenti di filtrare facilmente i post e le pagine in WordPress.

Video tutorial

Subscribe to WPBeginner

Se il video non vi piace o avete bisogno di ulteriori istruzioni, continuate a leggere.

Consentire agli utenti di filtrare facilmente i post e le pagine

La prima cosa da fare è installare e attivare il plugin Search & Filter. Per maggiori dettagli, consultate la nostra guida passo passo su come installare un plugin di WordPress.

Dopo l’attivazione, il plugin aggiungerà una nuova voce di menu denominata Search & Filter alla barra di amministrazione di WordPress. Facendo clic su di essa si accede alla pagina di utilizzo del plugin con una documentazione dettagliata su come utilizzarlo.

Search & Filter plugin documentation

Il plugin Search & Filter è dotato di uno shortcode che accetta diversi parametri per visualizzare le opzioni di filtraggio. È possibile utilizzare questo shortcode in un post, in una pagina o all’interno di un widget di testo.

[searchandfilter fields="search,category,post_tag"]

È anche possibile utilizzare lo shortcode come tag del modello nei file del tema di WordPress, come in questo caso:

<?php echo do_shortcode('[searchandfilter fields="search,category,post_tag"]'); ?>

In questo modo verranno visualizzate le opzioni di filtraggio con i campi di ricerca, categoria e tag.

Filter posts by category and tags

Per impostazione predefinita, il plugin accetta come campi la ricerca, la tassonomia, il post_type e la post_date.

Vediamo un altro esempio. Questa volta includeremo i campi categoria, tag, tipo di post e data.

È necessario utilizzare lo shortcode in questo modo:

[searchandfilter fields="search,category,post_tag,post_types,post_date"]

Ecco come apparirebbe:

Adding all fields to the filter

Ora, invece di utilizzare un campo di selezione a discesa, è possibile utilizzare delle caselle di controllo e aggiungere delle etichette per ogni campo. Per farlo, è necessario aggiungere altri due parametri allo shortcode.

Se si utilizza una pagina separata per visualizzare i post del blog, è possibile aggiungere questo shortcode alla pagina.

[searchandfilter headings="Select categories:" types="checkbox" fields="category"]

Allowing users to select multiple items in the filter using checkbox

Se si utilizzano più campi, tipi e intestazioni, è necessario assicurarsi che gli elementi siano nello stesso ordine per ogni parametro.

Vediamo un altro esempio. Questa volta stiamo aggiungendo i campi categoria, tag e tipo di post con intestazioni e tipi di campo diversi.

[searchandfilter headings="Post type, Category, Tag" types="checkbox, select, select" fields="post_types,category,post_tag"]

Ecco come apparirà sul vostro sito:

Advance filtering with headings and different field types

Consultare la pagina di documentazione del plugin per ulteriori modi di utilizzare lo shortcode.

È possibile utilizzare questi shortcode anche all’interno di un widget di testo. Se lo shortcode non funziona nel widget di testo, consultare la nostra guida su come utilizzare gli shortcode nei widget della barra laterale di WordPress.

Speriamo che questo articolo vi abbia aiutato a capire come permettere agli utenti di filtrare i post e le pagine in WordPress. Potreste anche voler vedere questi consigli pratici per aumentare il traffico sul vostro sito WordPress.

Se vi è piaciuto questo articolo, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

17 commentiLascia una risposta

  1. 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!

  2. Himanshu Gautam says

    hi
    I am using this plugin
    is there any option to select a category without hitting the submit button?

  3. 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.

      Admin

  4. 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.

  5. 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

  6. 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?

  7. 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?

  8. 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.

  9. 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

  10. 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?

  11. 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).

  12. 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

  13. 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.

  14. 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!

  15. 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.

      Admin

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.