Skip Navigation

[Resolved] Custom query

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 12 replies, has 2 voices.

Last updated by Shane 6 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#908376

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.

#908565

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

Thank you for contacting our support forum.

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.

See the documentation below for more information on this.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#1-using-the-empty-function

Thanks,
Shane

#908613

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.

#908974

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

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.

Our documentation as an exact example like this.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/#1-using-the-empty-function

[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.

Please let me know if this helps.
Thanks,
Shane

#909013

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.

#909067

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

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.

Please let me know if this helps.

Thanks,
Shane

#911619

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?

#911868

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

That is not possible which is why i suggested to use the conditional shortcode to check each post and only display the ones with the url Like this.

[wpv-conditional if="( NOT(empty($(wpcf-test-field))) )"]
 
This field is not empty
 
[/wpv-conditional]

Thanks,
Shane

#911975

That doesn't work either.

 
[wpv-conditional if="( NOT(empty($(wpcf-registration-url))) )"]

[wpv-post-body view_template="Loop item in Announcement List" suppress_filters='true']

[/wpv-conditional]

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.

#911982

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

Would you mind allowing me to check on this for you ?

The private fields will be enabled for your next response.

Thanks,
Shane

#912442

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

The code actually works to me because the view is showing up empty.

I checked all the posts and non of them have the registration-url filled in so that means they should not show up.

Thanks,
Shane

#912450

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.

#912453

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

Awesome so this issue is resolved correct?