Enable Draft Filter by Download Category?
-
Hi,
Can we filter Downloads (Draft) by Category like Posts?
I dont see that filter, only applied for pubished ones.
Br,
-
Hi,
Sorry I can not get your point clearly.
Do you want to fetch “Downloads” which are in “Draft” status?
I want to filter all Downloas which have “Draft Status” by Download Category :D!
Hi @gianghl1983
Please try below code snippet. In that you jet need to change ‘DOWNLOAD CATEGORY ID’ to your desired download category id. You can use ‘category slug’ also with given information.
// WP Query Parameters $args = array ( 'post_type' => 'download', 'post_status' => array('draft'), 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page'=> 10, 'tax_query' => array( array( 'taxonomy' => 'download_category', 'field' => 'term_id', // slug (If you want it by term slug not id) 'terms' => 'DOWNLOAD CATEGORY ID', )) );
Please try and update me for the same.
@pratik-jain Thank you!
Maybe I am not clear enough. What I want is to filter Downloads in Admin Dashboard (Like filter post by Category, Status…) ??
Hi,
The code snippet which I have provided you is a Query arguments to get Draft status product for particular category. You can use this argument with WP Query OR get_posts() function. You can modify this code as per your requirements.
Now can you provide me rough screenshot how you want in admin? so It would be good for better understanding.
@pratik-jain Thank you!
You can filter default Post (Draft) by Category by using WordPress Filter : https://i.imgur.com/PB4x79Y.png
With EDD, you can not filter for Draft Downloads.
Hi,
Thanks for providing the screenshot. I think there is something, I can filter Draft status download (product) with category in WordPress admin area.
Please refer below screenshot
https://screenshots.firefox.com/RLSiZTTtDmTIh6jX/192.168.1.53Can you please provide me EDD admin area screen?
@pratik-jain Thank you!
Please try to filter Draft Downloads by Category.
I took some screenshots:
1. For All Downloads – you can see only 1 published download counted in Catgegory 1: https://imgur.com/iA1gajP
2. In Drafs Tab: There is still only 1 download counted in Category 1 (published one), could not filter by Category 2, 1: https://imgur.com/dnzDTva
Hi @gianghl1983
Thanks for the screenshots. I have checked all the things at my side and compare the scenario with WordPress default post filter behavior.
Yes, EDD has minor issue. Actually EDD does not show ‘Empty Terms’ to dropdown. When term is assigned to only one product and we make it draft then it counts becomes zero (No download is assigned to it). It becomes empty.
EDD does not show empty category in dropdown so you are unable to filter it. If you assign category to any published download then you can filter draft download also.
You can use below code snippet for temporary solution, You can put this code to your theme / child theme functions.php file. I will report this to EDD bug center and they will resolve this. Thanks!
function _edd_modify_get_terms( $term_query_vars, $term_taxonomies ) { global $typenow, $pagenow; $term_taxonomies = is_array( $term_taxonomies ) ? $term_taxonomies : (array)$term_taxonomies; if( is_admin() && $typenow == 'download' && $pagenow == 'edit.php' && in_array( 'download_category', $term_taxonomies ) ) { $term_query_vars['hide_empty'] = false; } return $term_query_vars; } add_filter( 'get_terms_defaults', '_edd_modify_get_terms', 10, 2 );
@pratik-jain Cool! Thank you so much!
Have a nice day ;)!
@pratik-jain It works perfectly. Only small matter: Show Total number of items in each Category (Draft status). At this moment it returns like this: Category Draft (0).
We still can filter by this Category Draft to get all downloads (Draft) in this category.
Thank you! ??
Hi @gianghl1983
Yes, It will show zero count. Actually it is a WordPress default behavior that category will not count the draft status post. It will only consider to publish state post and it is a perfect behavior.
Glad to know that the solution worked for you ??
Kindly mark the topic as resolved.
@pratik-jain Thank you! Anyway to count DRAFT state also by modifying code…?
Hi @gianghl1983
Yes, we can do but I recommend you to should not do this.
As we had talk that it is a WordPress default behavior and it does not include count within it until post is in publish state.
This is the reason that’s why WordPress do not show count in default post section category dropdown.You have to run unnecessary and complex query for this which is not actually needed. I hope it make sense.
@pratik-jain Okie, thank you!
Have a nice day! ??
- The topic ‘Enable Draft Filter by Download Category?’ is closed to new replies.