Skip Navigation

[Resolved] Hidden item menu on archive page

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by ilariaB 3 years ago.

Assisted by: Minesh.

Author
Posts
#2428739

Hello,

On the website, I created an archive page ( hidden link ) which there is on the left a menu. The first part of the menu has the list of regions "piemonte, lombardia,...". It's possible to remove automatically some of these items if they are empty? For example, if you select "lombardia" and click on "Cerca farmacie" the next page show the message " Non ci sono farmacie..."

I don't want to show items on the menu the doesn't have any results

thanks

#2428827

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share admin access details and let me see if I'm able to share any workaround for this issue.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2429365

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I tried to follow the link you shared but I do not get access to admin.

Could you please share admin access details.

I have set the next reply to private which means only you and I have access to it.

#2429385

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now: hidden link

To filter the terms displayed with the taxonomy filter with the view, Toolset offers the hook "wpv_filter_taxonomy_frontend_search_available_terms" using which we can fitter the taxonomy filter terms.

I've added the following code to "Custom Code" section offered by Toolset:
=> hidden link

add_filter( 'wpv_filter_taxonomy_frontend_search_available_terms', 'func_show_only_terms_having_posts_in_filter', 10, 3 );
 function func_show_only_terms_having_posts_in_filter( $terms, $taxonomy, $view_id ) {
    
    $terms_to_return = array();
  if($view_id == 235 && $taxonomy =='regione'){
    
    foreach ( $terms as $term ) {
        if (  $term->count !== 0 ) {
            $terms_to_return[] = $term;
        }
    }
  }
        return $terms_to_return;
  
}

More info:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_frontend_search_available_terms

#2429391

Hello,

there is still an error... fatturato is empty and it must be visible

#2429399

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now: hidden link

I've adjusted the code added to "Custom Code" section as given under:

add_filter( 'wpv_filter_taxonomy_frontend_search_available_terms', 'func_show_only_terms_having_posts_in_filter', 10, 3 );
 function func_show_only_terms_having_posts_in_filter( $terms, $taxonomy, $view_id ) {
    
    $terms_to_return = array();
  if($view_id == 235 && $taxonomy =='regione'){
    
    foreach ( $terms as $term ) {
        if (  $term->count !== 0 ) {
            $terms_to_return[] = $term;
        }
    }
    $terms = $terms_to_return;
  }
  return $terms;
  
}

I can see it works as expected.

#2429407

It works perfectly thanks so much but, I don't understand what change you did to the code because I can't see the difference...Can you explain, please?

#2429413

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

This line of code is added:

$terms = $terms_to_return;

And the return statement is changed from:

return $terms_to_return;

To:

return $terms;
#2429421

Yes, I checked well before you reply and I saw it... thanks so much, I learned a new thing about your plugin 🙂

#2429425

My issue is resolved now. Thank you!