I've gotten basic views I needed to display. But in my "Performers" CPT, I have the "Active" checkbox field. Its configured as default to save with value "1" with checked.
Now in my view I've created without any filters it displays and formats the CPT data properly. But I would like it to only display the CPT records that are "Active". I create a Query Filter with Custom Field Filter, "Select items with field: Active Performer is a number equal to 1".
But no results are returned. Suggestions?
Second question. What is better practice? I have two similar fields for Performers CPT, "Active" and "Featured". Which is better? Create as a custom field in the CPT or CPT Taxonomies?
Thanks,
Hello,
Q1) But no results are returned. Suggestions?
Yes, it is expected result.
Since you are querying the post type "Performance", but the custom field "Active" is in another post type "Performers", there isn't field "Active" in post type "Performance", so it conducts the problem:
But no results are returned
Views is using WordPress class WP_Query to query the posts, if you filter the posts by a custom field, those posts must have the specific custom field.
You might consider to move the field "Active" into post type "Performance"
Q2) Create as a custom field in the CPT or CPT Taxonomies?
In this case, I suggest try with custom checkbox field, since there is only two values in it: 1 or empty.
If there are multiple options, and you will need to add more options in future, you can consider custom taxonomies.
For your reference.
I want to create a table schedule similar to this. I can produce this view, until I try and filter by the performers that are "Active". Then no results are returned. When I have "Performers" CPT selected as the view to display. If I select any of the other CPTs then I can't properly sort by times.
Times Stage Performer
10:00am - 1l:50am Main Stage David Marsh
10:15am - 11:00 Cultural Center Irish Dancers
This is my CPT configurations.
Three CPTs
Performers - the performers/events in festival
Locations - the locations/stages of performances
Performances - includes the start/end times of the performances
Taxonomies
Performer Categories - two checkbox fields; active, featured
Relationships (one to many)
Performers ->> Performers (performer-performance)
Locations ->> Performers (location-performance)
Suggestions on how to get a view like the above and filter on only the Performer "active" taxonomy. This is still early in project I would be willing to change how my CPTs are created if needed.
Thanks for the details, as I mentioned above, there isn't such kind of built-in feature within Toolset Views plugin.
Currently, you can try custom codes, for example:
1) Create a post view "my-view", query "performance" posts
2) Use Views filter hook wpv_filter_query to trigger a PHP function
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
3) In this PHP function, do these:
a) Get all "Performers" post IDs which is assigned with term "active":
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
b) Use above "Performers" post IDs to get all related "performance" posts:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts
c) Use above "performance" post IDs to add a filter into the post view "my-view"
https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
post__in (array) – use post ids. Specify posts to retrieve.
For your reference.
I decided it best to split the "featured" as a checkbox field on both CPTs Performers and Performances. As in my case their are both featured performers and featured performances. Two seperate queries and displays. Thanks for your assistance.