7 – Filter Content and Files using the same Taxonomy term filter in Search API

I have several File (File Entity) and Content (nodes) types both referencing the same Topic taxonomy using the same field (one field, reused). The contents of these files/content are indexed in the same index using Search API (multi-type index). I also have a view that lists down the contents of that index, showing a mixed list of files and content.

Now what I’d like to do is filter the results by the Topic taxonomy using only one dropdown filter, e.g. If I want to find files and content related to “Science”, I would just select “Science” from the Topic filter, and the view will show all the files and content related to “Science”.

The problem is that when I add a filter to the view, Drupal presents two filter options for Topic, one for the Topic field on the File entity and another for the Topic field on the Content entity – not just one filter. I’ve already tried Combined Filters, but that doesn’t give me a dropdown of Topics. Also hit a dead end on Search API aggregated fields.

How does one filter a view of both files and content by just one taxonomy filter?

categories – How to show the category of custom taxonomy

In the built category, we can use has_category() and the_category() to show if the post has category and the name of the category.

Now, I am using my custom post type and custom taxonomy. The above two functions are invalid in this case. I wonder what’s the API to use here? Thank you.

menu for custom type and taxonomy at the same time or filter by type

I have two custom types (eg: Cooks and Restaurants) and both have a shared taxonomy (eg: specialty). I want a menu that pulls all the restaurants based on a specific specialty but there doesn’t appear to be a way to use appearance -> menu to add the specialty taxonomy so that it only links to restaurants but not to cooks. eg: a menu that basically does a search for one type with that taxonomy match but doesn’t also pull the other type with that taxonomy match

To be clear I can get the taxonomy with both by simply editing a menu, placing a check-mark in the taxonomy name in screen options and then adding the individual taxonomy terms… I just don’t see how to filter the results to be only a single type. I assume that I will need to do this with some code but wanted to be sure I wasn’t over-engineering it.

Is there a way that is built into WordPress that would allow this to be done or am I looking at writing some custom code/adding a plugin?
Alternately… what keywords should I have used to find an answer to this? It seems like anything that is remotely related is dealing with using a taxonomy with the same name as a type. I also looked at the title (at a minimum) of all the advanced-taxonomy-queries tagged questions when I discovered that but none seemed to be like my issue (though many were interesting in other ways).

Custom field with terms from another taxonomy

I have a custom taxonomy A with some terms (A1, A2,A3, etc) and a second custom taxonomy B.
I want to create a custom field in taxnomony B which will be a dropdown menu with the terms from taxonomy A.
I am able to create custom fields with texts and to get the terms from taxonomy A with get_terms(). The get_terms() function, returns an array of object (every object is a term). I am not sure how to build the dropdwon. How can I connect them?
Thank you

how to create single page for custome post type, custome taxonomy with rewrite rule

i am creating wordpress website. i have made a cpt like ‘news_post_type’ with rewrite url. but my single page and archive page not working. here is my both files name (archive-news.php, single-news_post_type.php)

below is custome post type url structure


i have used below code for custome post type

for register post type

add_action('init', 'cpt_news');

function cpt_news() {

$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats

$labels = array(
'name' => _x('News', 'plural', 'snt'),
'singular_name' => _x('News', 'singular', 'snt'),
'menu_name' => _x('News', 'admin menu', 'snt'),
'name_admin_bar' => _x('News', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New News'),
'new_item' => __('New News'),
'edit_item' => __('Edit News'),
'view_item' => __('View News'),
'all_items' => __('All News'),
'search_items' => __('Search News'),
'not_found' => __('No News found.'),

$args = array(
'supports' => $supports,
'labels' => $labels,
'description' => 'Holds our News and specific data',
'public' => true,
'taxonomies' => array( 'news_year' ),
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'can_export' => true,
'capability_type' => 'post',
'show_in_rest' => true,
'query_var' => true,
'rewrite' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_position' => 6,
'menu_icon' => 'dashicons-megaphone',

register_post_type('news_post_type', $args); // Register Post type

For Custom texonomy

function news_year() {

    $labels = array(
        'name'                       => _x( 'Year', 'Taxonomy General Name', 'snt' ),
        'singular_name'              => _x( 'Year', 'Taxonomy Singular Name', 'snt' ),
        'menu_name'                  => __( 'Years', 'snt' ),
        'all_items'                  => __( 'All Items', 'snt' ),
        'parent_item'                => __( 'Parent Year', 'snt' ),
        'parent_item_colon'          => __( 'Parent Year:', 'snt' ),
        'new_item_name'              => __( 'New Year Name', 'snt' ),
        'add_new_item'               => __( 'Add New Year', 'snt' ),
        'edit_item'                  => __( 'Edit Year', 'snt' ),
        'update_item'                => __( 'Update Year', 'snt' ),
        'view_item'                  => __( 'View Year', 'snt' ),
        'separate_items_with_commas' => __( 'Separate Year with commas', 'snt' ),
        'add_or_remove_items'        => __( 'Add or Remove Year', 'snt' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'snt' ),
        'popular_items'              => __( 'Popular Year', 'snt' ),
        'search_items'               => __( 'Search Year', 'snt' ),
        'not_found'                  => __( 'Not Found', 'snt' ),
        'no_terms'                   => __( 'No items', 'snt' ),
        'items_list'                 => __( 'Year list', 'snt' ),
        'items_list_navigation'      => __( 'Year list navigation', 'snt' ),

    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'query_var'                  => true,
        'show_in_rest'               => true, // for show in cpt
        'rewrite'                    => array('slug' => 'news-year')
    register_taxonomy( 'news_year', array( 'news_post_type' ), $args );

add_action( 'init', 'news_year', 0 );

Post type link hook

function change_link( $permalink, $post ) {
    // die();
    if( $post->post_type == 'news_post_type' ) {
        $resource_terms = get_the_terms( $post, 'news_year' );
        $term_slug = '';
        if( ! empty( $resource_terms ) ) {
            foreach ( $resource_terms as $k=>$term ) {

                // The featured resource will have another category which is the main one
                if( $k == 0 ) {
                     $term_slug = $term->slug;;
        $permalink = get_home_url() ."/news-updates/" . $term_slug . "https://wordpress.stackexchange.com/" . $post->ID.'-'.$post->post_name;
    return $permalink;


custom taxonomy – Displaying all posts by category and showing content on click

I am building a WordPress site for a composer who has written over 200 pieces of music. Each is a custom post (work), organised by a hierarchical custom taxonomy/category (type – being orchestral, vocal, etc).

I need to build a catalogue page in which all works are displayed in lists by type:

Orchestral Works:

Vocal Works:


The user can add categories to the list, so I can’t simply write a query for each category. The catalogue page needs to check the list dynamically.

So far so good. This can be achieved – and sorted the way I need – like this:

    $cat_terms = get_terms(
            'hide_empty' => true,
            'orderby' => 'name',
            'order' => 'ASC',
            'number' => 9999 
    if( $cat_terms ) :
    foreach( $cat_terms as $term ) :
    echo '<h5>'. $term->name .'</h5>';

<?php $args = array(
    'post_type' => 'work',
    'posts_per_page' => 9999, // Assuming no-one is this prolific
    'post_status' => 'publish',
    'tax_query' => array(
            'taxonomy' => 'type',
            'field' => 'slug',
            'terms' => $term->slug,
    'ignore_sticky_posts' => true,
    'meta_key' => 'date',
    'orderby' => 'meta_value',
    'order' => 'DESC'
    $_works = new WP_Query( $args );
        if( $_works->have_posts() ) :
            echo '<table>';
                while( $_works->have_posts() ) : $_works->the_post(); ?>
                        <td><?php the_field('date'); ?><td><?php the_title(); ?></td>
                <?php endwhile;
            echo '</table>';

I then need to be able to display the content of the CPT (a small amount of data in a few custom fields) in another div in the same page (and not link out to a single-work.php template as would be more usual). This would be like a tabbed content effect – one posts’ content displayed at a time, chosen from the category-based list on the page.

enter image description here

I could create this second part by loading everything and toggling visibility via jQuery but that would mean loading 200+ posts with the page and making them invisible, which strikes me as a terrible idea.

Is it possible to fetch/load the content of the selected post dynamically on click, so only the posts required are queried beyond the initial list? How would this be handled, and where would I begin with it?

8 – Hide taxonomy term from a view filter where the filter results are empty

I have several nodes and several taxonomies, but only some nodes have taxonomy relationships.

enter image description here

My problem is that the taxonomy filter shows those terms too which don’t have any node relationships at all, example:

enter image description here

So even if I don’t have any nodes in “Category 1”, the term will show up in the filter.

Is there a way to remove those taxonomy terms from the filter which have no content associated to them?

jquery – Filter data based on Taxonomy value

I am building a search web part in which, I am filtering the data from the SharePoint document library based on the value in the skillset column.

It is a managed metadata column.

Below is the structure of the single record.

ID: 746
OfficeLocation: {Label: "India", TermGuid: "7f1ef83c-0dbd-463d-8fda-5d1ea4506bb5", WssId: 5}
Skillset: (4) ({…}, {…}, {…}, {…})
Title: null

The skillset is again an array of objects as below.

enter image description here

0: {Label: "ASP.Net", TermGuid: "0207fb4e-cff9-43b9-8c27-2225ff2bde78", WssId: 24}
1: {Label: "Java", TermGuid: "4b01e476-0864-434b-9dfe-d576b4451c3f", WssId: 7}
2: {Label: "Javascript", TermGuid: "1d0c4e05-c1f6-4f3a-accd-66e5f334d3f0", WssId: 32}
3: {Label: "SQL Server", TermGuid: "4626fe15-bc26-462a-bc6c-9d1701ba14ed", WssId: 30}

Here, I want to filter these records based on the skillset value.

So, if I enter “java” as my search keyword then only those records should come which has the skillset label value as “java”.

Currently, I used the .some function which returns the records who has the skillset javascript because it contains the word java in it.

 (f) =>
  f.Skillset.length > 0 &&
  f.Skillset.some((s) => s.Label == element.name)

Can anyone help here to filter the data with the exact skillset?

information architecture – Should the taxonomy of forms and publications search match the site IA?

We have a search for forms and publications feature on a wide range of subjects on a government site for our users. We’re trying to develop a filter option that will narrow the results based on a subject (e.g. Electrical). The content producers of the forms and publications have proposed subjects that matches the information architecture of the site pages. As a UX/IA designer, this doesn’t seem the right approach given the changing nature of the site architecture, and some proposed subjects would be too-specific, resulting in few results. I need to provide qualified reasons to reject their proposed taxonomy. Are there resources from studies that could help?

8 – How do I show an exposed view filter in a block only on relevant taxonomy term pages?

How to make a block vocabulary-specific

You can use the Block Visibility Groups module in conjunction with the Vocabulary Condition module (linked on that page). Using those two modules together will give you a checkbox on the block to pick the vocabulary it should be shown for.

If you want to do it programmatically, the Vocabulary Condition module should be a good code reference. There’s also another Vocabulary Condition module (same name, ugh!) which could also be a good reference.

Alternative idea: Use different view pages for each vocabulary

If you’re using the default taxonomy term view provided by core, I’m pretty sure you can customize it so that you have one page for terms with the Product vocabulary and another for the Blog category. Then you can simply expose the filter on the view page for the relevant vocabulary.