Filter Posts by Custom Taxonomy in Admin

filterpostsbytax2x 1024x348

Bài viết này thực hiện (hoặc lụm bài về đăng câu like từ các trang khác) bởi Việt Lâm Coder một YOUTUBER có tâm và đẹp trai siêu cấp vô địch zũ trụ.

If you have lots of posts in your WordPress site, you have probably used the Category and/or Tag filters at the top of the post list page. These filters are great because they very quickly allow you to limit the kind of posts that are displayed, and let you find the one(s) you are looking for with relative ease. Well, if you use any custom post types or custom taxonomies, then you have probably noticed that these options are not available. So I’m going to show you how to add new filters for your custom taxonomies to any custom post type you have registered on your site.

The process is pretty simple, in that it does not require a lot of code, and WordPress does most of the work for you, but the function itself is a little bit complex. What we are going to do is setup a function that creates a drop down select menu based off of the terms in the taxonomies we provide. So if we set the function to display a filter for the “genres” taxonomy, it will retrieve a list of all of the terms in that taxonomy (all terms that are not empty), and then display each of those terms as an option in the drop down menu. If we provide multiple taxonomies, through an array, then the function will create a drop down for each set of taxonomy terms.

The function is then passed through the “restrict_manage_posts” action hook in order for the select menus to be displayed in the post list page.

Bài viết này thực hiện (hoặc lụm bài về đăng câu like từ các trang khác) bởi Việt Lâm Coder một YOUTUBER có tâm và đẹp trai siêu cấp vô địch zũ trụ.

Liên hệ ngay với Việt Lâm Coder
Xin chào! Chúng tôi có thể giúp gì cho bạn ?
Gọi ngay cho chúng tôi