Skip Navigation

[Resolved] Show parents where children have no date fields more recent than 3 months

This support ticket is created 8 years, 5 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.

Our next available supporter will start replying to tickets in about 1.32 hours from now. Thank you for your understanding.

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 14 replies, has 2 voices.

Last updated by gavinS 8 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#353852

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.

#353994

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

#354265

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?

#354452

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

#354472
All communications View.png
View Settings.png

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?

#354488

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.

#354522

Um.. I don't see any 'private detail box'?

But yeah, sure I'll set this up.

#354527

Hi Luoy

You can try log in at top1.gammawebsolutions.co.za

User: Luoy

Password: ****

#354783

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

#354892

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

#354899

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?

#355086

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

#355256

Hi Luoy

Sorry, another one of your support guys had messed with the function.php.

You should be able to get in now..

#355375

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.

#355404

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?

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.