I made an 'announcement' custom post type type. I have 2 taxonomies for it and some custom fields. I know how to filter by taxonomy but how do I make a view that only shows certain posts, IF a certain custom field is filled out?
Basically I want the view to show only the announcements where the 'registration-url' custom field has something in it. Also likewise, a view to only show announcements where the registration-url custom field does NOT have something it.
What you can do is to create the view like how you would normally and then add a conditional to the view loop output to check if the field is not empty and display the post content.
This will filter out all the posts that don't have the content filled out.
Thanks. I do know how to not show a field if there is an empty value but I need to know the right code to do this:
Using the view 'announcement-grid' , only show posts that are in the taxonomy of 'registration-announcements' AND do NOT have an empty value in the custom field 'registration-url'.
I can't figure it out from the help page you sent.
What you need to do is to add a taxonomy filter to your view that will list only the post from the registration-announcements Taxonomy.
Then in the view loop output you will need to add the conditional to check if the custom field is not empty. Within the conditional you will add the information that you want to display if the field is not empty.
[wpv-conditional if="( NOT(empty($(wpcf-test-field))) )"]
This field is not empty
[/wpv-conditional]
In this example there is a field with the slug, test-field, however these fields are saved with the wpcf- prefix attached. This is why you see the wpcf-test-field in the example. With your custom field it will be the same format of wpcf-custom-slug.
Thanks... so I have to create a whole new view to do this? I already know how to do that and then do conditionals... what I was wanting is one shortcode to use like (and this is just example... not using the items I spoke of earlier):
[wpv-view name=staff-list department=leadership query=only show items that have 'staff-email' filled out]
Obviously the query would be a code but you get the idea.
SO you want it so be filtered by a shortcode parameter.
This is possible by just editing the query filter on the view and set it to get the information by a shortcode parameter. It should give you the parameter to add to the view shortcode, then you just add that text to the shortcode.
Lets say you've selected the shortcode parameter for the taxonomy filter and it gives you the param "wpvtax" then when calling the view you will do it like this.
[wpv-view name='my-view' wpvtax='taxonomy']
So you will pass the taxonomy term into the view that you want to filter for.
I already have [wpv-view name='my-view' wpvtax='taxonomy']. I'm asking how do I filter it even further in the shortcode to show only posts that have the custom field registraiton-url filled in?
Just shows no posts. Even I put that conditional inside the loop item area, it still doesn't show any events, let alone just the ones with that registration-url field filled out.
Hmm I had 2 of them with registration urls in there yesterday. My other admin might have removed them to test out the feature. Thanks for taking a quick check.