Skip Navigation

[Resolved] View Filter to check if textfield has text or not

This support ticket is created 5 years, 8 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Beda 5 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#1239339

I want to build a view where I can filter whether or not a textfield on my post type contains text or not. For example, I have a projects post type. Besides other fields and taxonomies, the post type has a WYSIWYG field called "references" (the customer of the project can write a reference about the project). The reference field can also be empty.

In my search, I now want to be able to filter my projects by "With references", "Without references" and "With and without Referece".

#1239352

It's not possible, because a field that has no content is not saved against the post, and hence, does not exist.
This is the same for any field type.

It's a feature that needs to be added to Toolset (ability to filter for exists or exists_not in metadata), and you'd have to submit this suggestion here:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

Currently, the best would be to create a Radio Field with 2 options (has and has no reference).
Then update all posts with the proper value and later create either a backend query or front end search in a View for that Radio field, which will let you choose either "has" or "has no" reference.
You can use a checkboxes search input to allow marking both, which then returns both results with "has" and "has not" value saved.

Please do not forget to submit the suggestion to our Product Manager to implement searches for not existing fields and update the current != comparison to make it smoother querying empty/not existing fields.
('compare' => 'NOT EXISTS', see https://codex.wordpress.org/Class_Reference/WP_Meta_Query)

#1239354

I see. Are there hooks to implement a custom filter? For example if I would add a HTML input myself (select with those three options) and before Toolset creates the query, I would read the value from that input and manually add it to the query?

#1239358

You can use Toolset Hooks, yes.
We have a large how-to DOC here https://toolset.com/documentation/programmer-reference/toolset-hooks/ and a detailed technical page about the single hooks here https://toolset.com/documentation/programmer-reference/views-filters/

You'd likely hook in the https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query hook.