This thread is resolved. Here is a description of the problem and solution.
Problem: I would like to create a custom shortcode that finds all the "person" posts where the author is the current logged-in User, and filter those posts by two custom fields. One of the fields must equal "Yes" and the other field is either blank or does not exist.
Solution: Use an associative array meta query to query by two custom fields:
I have created a view with a loop to display all CPT 'People'. I need to add a query filter that only brings back 'People' where the 'message-for-recipient' field has been filled in and is not blank.. I can't seem to find a way to do this..
e.g. Message For Recipient is a string !blank or !empty
Hi Shane
The problem is that I have a <h2> Title that displays between the item found and loop begin section... so this still displays even though the field is empty...
Regards
Geoff
The problem is that the <h2></h2> and <p></p>tags I need to hide/display (depending on whether posts are found is outside of the loop so the conditional code you suggest wouldn't work. Here is the loop below. I only need to show the <h2></h2> and <p></p> if the items found have the field 'message-for-recipient' not empty..so the filter needs to be in the search rather than the view....e.g.
'Select items with field: message-for-recipient is not empty'
Hope that makes sense
Best wishes
Geoff
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<h2>Messages</h2>
<p>It is my intention that my Trustees deliver the following messages to my intended beneficiaries, either electronically or in hard copy. These personal messages should not be shared with anyone other than the beneficiaries listed, and as a non testamentary document these messages should be excluded from public availability.</p>
<ol class="wpv-loop js-wpv-loop">
<wpv-loop>
[wpv-conditional if="( $(wpcf-message-for-recipient) ne '' )"]<li>[wpv-post-body view_template="loop-item-in-messages-to-my-possession-recipients" suppress_filters = "true"]</li>[/wpv-conditional]
</wpv-loop>
</ol>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"][/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
I think you may have misunderstood...To demonstrate I have created a single 'cash gift' which is actually a CPT 'PERSON'... but have left the message-for-recipient field blank..
So in the view in question it still finds this one entry and although doesn't output anything for the field it still displays the <h2> and <p> tags after the items-found tag... I've attached a screenshot to show you this:
I think you still don't understand..I will try to explain more clearly...
The view returns CPT 'PERSON' that have either 'Cash Gift' OR 'Possession' eq to 'Yes'
The CPT may or may not have the 'message-for-recipient' field filled in.
In the view itself if the filter finds any items it will display :
[wpv-items-found]
<h2>Messages</h2>
<p>It is my intention that my Trustees deliver the following messages to my intended beneficiaries, either electronically or in hard copy. These personal messages should not be shared with anyone other than the beneficiaries listed, and as a non testamentary document these messages should be excluded from public availability.</p>
And also Loop Items...
[/wpv-items-found]
However sometimes the filter will find CPT 'PEOPLE' that do not have the 'message-for-recipient' field filled in. If this is the case I need the :
<h2>Messages</h2>
<p>It is my intention that my Trustees deliver the following messages to my intended beneficiaries, either electronically or in hard copy. These personal messages should not be shared with anyone other than the beneficiaries listed, and as a non testamentary document these messages should be excluded from public availability.</p>
To be HIDDEN... or for the filter to only find posts where the 'message-for-recipient' field is filled in...
So either:
1. The filter to only find posts where the 'message-for-recipient' field is filled in...
2. Hide the <h2> & <p> part on the items found section if ALL of the returned posts do not have the 'message-for-recipient' field filled in...
Correct I believe I understand. In this case you will only want your view to display PEOPLE that only have the message for recipients filled in.
Can you create just 2 people for my account to test ? One with the message field filled out and one without ?
We should be able to achieve this by using a query filter as you've done but i'm not sure why its not working as intended so I need to test it further with these 2 options.
Thank you for your continued patience as we work through this one.
Thanks,
Shane
Correct I believe I understand. In this case you will only want your view to display PEOPLE that only have the message for recipients filled in. ------No this is where there is a misunderstanding - The filter already does this... It is the :
<h2>Messages</h2>
<p>It is my intention that my Trustees deliver the following messages to my intended beneficiaries, either electronically or in hard copy. These personal messages should not be shared with anyone other than the beneficiaries listed, and as a non testamentary document these messages should be excluded from public availability.</p>
...part that I need hiding if the found items ALL have no message for recipients.. SO I was either suggesting :
1. The filter to only find posts where the 'message-for-recipient' field is filled in...
2. Hide the <h2> & <p> part on the items found section if ALL of the returned posts do not have the 'message-for-recipient' field filled in...