Skip Navigation

[Resolved] Filtering data on the basis of grand parent post relationship

This support ticket is created 4 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by deepS 4 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1361165
Screenshot_1.jpg

HI,
I have a job website with custom posts 'Jobs' and related parent post 'Places'. These 'Places' are then connected with 'States'. So, 'State' posts become grandparents for 'Job' posts.
Now, I want to filter these job posts based on selected 'State' posts, so that I can show how many job posts are there in the 'States'. How to do this?
Here is the screenshot of single job post.

#1361229
#1361233

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see you did not close the chat ticket. Please feel free to mark this ticket as resolved.

#1361319

Thanks for your support. I have almost created the view with your help that I required. But one last thing I want to arrange the posts based on the 'Last date of application/Interview' (a custom field) and not as per the date of the post. Please help. Thanks.

#1361837

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I already see that you set the custom field 'Last date of application/Interview' at the ordering section of the view. Is it not soring correctly?

#1361875

No, it's not working. You can see the black box beside the post where days remaining to the last date of application is shown. It's not in any order while on my homepage you can see it in ascending order.

#1361903

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As you know - you are using the nested views.

So, we have a view that filters for state, then places related to states and then jobs related to places. So we are looping through the top-level view state to bottom level view jobs.

So, for instance, For Maharastra state you have 9 places, so places view will loop through those 9 places one by one and display the jobs, which means the order will work for each loop instance of places view and it will display the order by restulst based on the places view loop.

#1361911

So how to resolve the issue to show data /post based on the 'last date of application'?

#1361925

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no way as its not logical.

Maharastra
- Place 1
--- post 1 - 15th oct
--- post 2 - 2nd oct
--- post 3 - 17th oct
- Place 2
--- post 4 - 7th oct
--- post 5 - 9th oct
--- post 6 - 5th oct
- Place 3
--- post 7 - 2nd oct
--- post 8 - 1st oct
--- post 9 - 5th oct

So, considering the above data, it should be displayed as:

Maharastra
- Place 1
--- post 2 - 2nd oct
--- post 1 - 15th oct
--- post 3 - 17th oct
- Place 2
--- post 6 - 5th oct
--- post 4 - 7th oct
--- post 5 - 9th oct
- Place 3
--- post 8 - 1st   oct
--- post 7 - 2nd oct
--- post 9 - 5th oct

I do not have any way to offer you to sort the results becasue its actually sorting based on your date field but as the view is added as nested view due to that nature you do not able to sort it as you want.

#1361955

Yah I understood your point. But let me give you one example (solution) provided by one of your support colleagues. This is a URL hidden link (15648) giving me results from Repeatable Field Groups (RFGs) of the posts accumulating from different Job posts according to the date order of the 'Last date of application/interview' for the jobs expired in last 7 days.
There are three views used here:
List Job Post Details posts (15646), Child view - expired-job-posts-within-7-days (15651) and Parent view - expired-job-posts-within-7-days (15650)
He has also used the following php code:

/*
*paginated view for weekly jobs
*/

add_filter( 'wpv_filter_query', function($query_args, $view_settings, $view_id){
    if(in_array($view_id, array(15646, 16601, 15430,) ) ){ // view "List Job Post Details posts" ID
        $query_args['orderby'] = 'post__in';
    }
    return $query_args;
}, 999, 3);


/**
 * Include custom code
 */
 

My suggestion/query is can we take this route to generate the desired results? Thank you.

#1361975

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I see you are listing job details (RFG). Repeating Field Group internally treated as a one-to-many relationship.

You added the view that lists the Job Post Details (RFG) as given under:

[wpv-view name="list-job-post-details-posts" ids='[wpv-view name="parent-view-expired-job-posts-within-7-days"]']

where:
- parent-view-expired-job-posts-within-7-days is retuning the IDs

So, above have two level strucure and now with your query you have three-level structure:

State -> places -> jobs

so you should try to follow the same structure as you used to display "Job Post Details (RFG)" but for three-level and check if you able to achieve your desired results by adding another wpv_query_filter hook.

#1364013

My issue is not fully resolved. Thank you!

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