I have a type called 'Client', which is a parent of 'Communication'.
'Communication' contains a date field.
Now I want to display a view of all clients who do not have any communications with dates within the last 3 months.
Dear gavin,
I suggest try with nested view:
1) parent view list Communication posts, filter with dates field within the last 3 months
2) child view list Client posts, filter with parent is set by parent view
Hi Luoy
Thanks for your help.
I'm not really clear on how to do the date filter.
I want to only show clients who have NO communication in the last three months. So I need to say if NOT post-date within 3 months. How do I do that?
I also need to make sure that it doesn't display clients who have a communication older than 3 months if they also have a communication more recently than three months.
Am I clear?
Sorry for the misunderstand, It needs some custom codes, I suggest you try this:
1) Create a view to list all clients posts
2) Use Views filter hook wpv_filter_query to add a custom filter:
a) query all Communication posts, filter with dates field within the last 3 months
b) Client posts, filter with parent is above qeury, then you will get all clients who have communication in the last three months.
c) Use Views filter hook wpv_filter_query to filter the view in step (1) with post__not_in in above step (b)
More help:
wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/
post__not_in (array) - use post ids. Specify post NOT to retrieve.
http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
Hi Luoy
Thanks for the help. Now I'm really confused. Heh.
So as I understand it, I need a view for all clients. (Done)
Then I need a view for all communications in the last three months. I'm trying to set that up but it's coming up as 'No Items found'.
I am using a custom field for date and time of the communication, as this might be different from the post date. I have attached a screenshot of the view options, and another showing all communications. You can see there are 4 communications, all within the last three months, but none of them come up in the view. Is there something wrong with my filter?
Could you duplicate same problem in a test site, and fill below private detail box with login details, also point out the problem page URL and view URL, I can try to setup a demo for you.
Um.. I don't see any 'private detail box'?
But yeah, sure I'll set this up.
Hi Luoy
You can try log in at top1.gammawebsolutions.co.za
User: Luoy
Password: ****
Sorry, I have edit your previous post to hide the password.
Since it needs custom PHP codes, I need test it in a live website, please fill below private detail box with login details and FTP access, also point out the problem page URL and view URL, thanks
Thanks for the details, I have made below modification in your test site:
1) add below codes in your theme/functions.php:
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){ return; }
It create a new shorcode to hide some extra div from below views output
2) create a view to list Communication posts, filter with
Select posts with custom field:
Date and Time is a number greater than PAST_MONTH(3)
hidden link
and only output the it's parent client post ID:
[hide-it][wpv-layout-start][/hide-it]
...
<wpv-loop>[wpv-post-id id="$client"],</wpv-loop>
...
[hide-it][wpv-layout-end][/hide-it]
3) modify the problem view, remove the filters, add below filter:
Exclude posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
4) edit the layout, replace the view cell with a content template view, using below codes:
[wpv-view name="communications-in-last-3-months" ids="[wpv-view name="show-parents-where-children-have-no-date-fields-more-recent-than-3-months"]"]
hidden link
Please test again, check if it is what you needed, thanks
Hi Luoy
Doesn't seem to be working. I have added another communication within the last 3 months for 'A client' and it is still showing up in the output?
I can not log into your test site, I get this:
Parse error: syntax error, unexpected ')' in /home/gammamag/public_html/top1/wp-content/themes/toolset-starter/functions.php on line 259
Please check it, thanks
Hi Luoy
Sorry, another one of your support guys had messed with the function.php.
You should be able to get in now..
I assume we are talking about the problem communication post:
hidden link
There isn't any parent client post in it, so it does not take effect.
Argh. You're right. What an idiot.
Sorry about that.
Thanks very much. I don't completely understand what you're doing here, but it seems to work. So now to just replicate it on the other real site.
This is what I think you're doing:
2) You create a view listing the client-Ids for all communications within the last 3 months.
3) You create a view of all clients, excluding the clients that have matching 'ids'
4) You create a content template to show the view in (3) excluding the clients in (2).
Is there any documentation on this sort of excluding view?
Is that about right? I'm not completely clear on what (1) is for? But I have noticed when trying to do other views with unordered lists, that often extra bullet points come up at the bottom of the view, so there are often extra pages full of empty records. Is this what this is for? To remove those?