Sunday, 6 August 2017

How to filter custom post type by meta field

By default, WordPress allows you to filter posts and pages by a couple of different parameters: namely, by publication and by category. Let’s say though that you’ve added a new meta field to your post or you’ve even created a whole new post type with all kinds of new meta fields. It would be nice to be able to filter your post type by one or more of those meta fields. What is a meta field?
Yes, good question. A meta field is a piece of custom data in addition to the main post content. For example, you’ve got a custom post type called ‘Book’ and you’ve created a meta field called ‘Genre’ where you can define each book’s genre.
I am assuming that you already know how to add meta boxes and meta fields to your content. If not, there’s some more information at and you don’t have to look very far for a number of different libraries and tools that will allow you to create the necessary code quickly and easily.
In my Wisdom plugin, I use a lot of different meta fields to store data about tracked websites. Wisdom is a plugin for plugin developers – you


No comments:

Post a Comment