Crocoblock / suggestions

The suggestions for CrocoBlock project
191 stars 78 forks source link

Filter not showing when there's only private posts #7532

Closed nicolasprigent closed 1 month ago

nicolasprigent commented 1 month ago

Describe the bug when I create a taxonomy admin filter and have only private posts, I don't see any filters in the dropdown.

To Reproduce Steps to reproduce the behavior:

  1. Create a new taxonomy and assign it to "post" post type for example. Create some test taxonomies in this new taxonomy
  2. Go to Jet Engine > Post Types, check "built in" to see "post" post type
  3. Edit "post" post type and create an admin filter related to the created taxonomy and save
  4. Go to "Articles" and put only private posts in it, and assign random taxonomies for them
  5. The filter is showing but is blank, no taxonomies are showing, thus it's not possible to filter private posts in admin

Expected behavior The filter should show the used taxonomies even if there's only private posts.

Screenshots attachment

Desktop (please complete the following information):

Additional context I've found the problem in the file ==> wp-content/plugins/jet-engine/includes/components/post-types/admin-filters.php

When I add "'hide_empty' => false," in the render_filters function (screenshot_1), I see the list of categories as expected. Only post count doesn't work but that's not as big of a problem than the filtering.

Screenshot_1 Screenshot_2

Would it be possible to add this really simple fix in a future update of jet engine so that I won't have to redo the fix on every plugin updates ? Thanks

nicolasprigent commented 1 month ago

The solution is documented here if you want : https://developer.wordpress.org/reference/functions/wp_dropdown_categories/#comment-content-886

Crocoblock commented 1 month ago

Hi @nicolasprigent

as you can see there is the hook-filter, where you can change the arguments image

use that hook for solve your issue

add_filter( 'jet-engine/post-types/admin-filters/taxonomy/args', function( $args ) {
   $args['hide_empty'] = false;

   return $args;
} );
nicolasprigent commented 1 month ago

thanks @Crocoblock, it worked ! I still suggest you to change this in your code since it's the default behavior of categories filter in wordpress. It would be more consistent in terms of user experience.