Skip Navigation

[Resolved] Displaying posts with Grandparent relationship

This support ticket is created 5 years 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
- 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/Karachi (GMT+05:00)

This topic contains 15 replies, has 2 voices.

Last updated by deepS 4 years, 12 months ago.

Assisted by: Waqar.

Author
Posts
#1380933

I have a custom post type 'A' with parent post 'B' and grandparent post 'C' (B and C have a parent-child relationship). Now can I display posts A with grandparent post C? At the same time, I want a chronological order in terms of date.

How to do this?

#1381613

Hi,

Thank you for contacting us and I'd be happy to assist.

To achieve this, you can create 3 different nested post views.

1. The grandparent view will be set to show the list of post type 'A'.

2. Its child view will be set to show the list of post type 'B', but only those which are related to the current post type 'A' in the grandparent view's loop.

Note: keep the loop item template of this view blank, if you don't want to show anything from post type 'B'.

3. The grandchild view will be set to show the list of post type 'C', but only those which are related to the current post type 'B' in the parent view's loop.

You'll find more details on the topic of nested views, in this guide:
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/#adding-a-view-to-a-view

To show these lists in chronological order, you can set these views to be ordered by "Post Date".
( example screenshot: hidden link )

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1381811

Hi,
This is a Job site where I display jobs filtered by Job location States (grandparent). The relations are like this:
State -> places -> jobs
Somehow I managed to create a view of the jobs based on your suggestion and other help. You can view the page here: hidden link
But I have two problems:
1. I want to hide the name of the States where there is no job and
2. I want pagination. But when I put it on a child level view it shows things in a different way. Without pagination, the page would be lengthier and lengthier.

Please help me to resolve the issue. Thanks

#1382137

Hi,

To suggest the best way forward to overcome both these points, I'll need to see how these views are set up in the admin area.

Can you please share temporary admin login details in reply to this message?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1383239

Hi,

Thank you for sharing the admin access.

First, I noticed a script error is being shown in the browser's console, on pages where the "Loop item in Homepage View" content template is used, because of this custom script:
( screenshot: hidden link )


$('div.text:empty').hide();

If your goal with this script was to hide the div around this "Walk-in-Interview" label when it is empty, you can simply move the entire div's code inside the conditional block:

Current:


<div class="text">[wpv-conditional if="( $(wpcf-walk-in-interview) eq '1' )"]Walk-in-Interview[/wpv-conditional]</div>

Updated:


[wpv-conditional if="( $(wpcf-walk-in-interview) eq '1' )"]<div class="text">Walk-in-Interview</div>[/wpv-conditional]

This way you won't have to include any script for this.

As for hiding the states, without any jobs, you can follow these steps:

1. For organization and structural uniqueness, you can wrap the output of each view's loop item, inside a special div container:

a). View: states-view-grandparent


<div class="states-wrap states-wrap-[wpv-post-id]">
	<hr>
	<h2>Jobs in [wpv-post-title]</h2>
	[wpv-view name="places-belongs-state"]
</div>

b). View: places-belongs-state


<div class="places-wrap places-wrap-[wpv-post-id]">
	[wpv-view name="jobs-belongs-places"]
</div>

c). View: Location wise Jobs


<div class="col-sm-12"><div class="jobs-wrap jobs-wrap-[wpv-post-id]">[wpv-post-body view_template="loop-item-in-homepage-view"]</div></div>

As a result, all post items from these views will be wrapped inside special identifier divs, based on the post type.

2. Next, in the "JS editor" tab, of your "states-view-grandparent" view, you can include the following script, which will hide all the states, without any job item:


jQuery(document).ready(function () {  
    jQuery('div.states-wrap').each(function() {
		if(jQuery('div.jobs-wrap', this).length < 1) {
			jQuery(this).hide();
		}
	});
});

As for the pagination, I'm afraid, it is not clear what is your planned requirement for this. The pagination shortcode and the settings are placed in the "states-view-grandparent" view, which seems to be working as expected.

However no pagination settings are defined in any of the nested views, but the pagination shortcode is repeated in the "Location wise Jobs" view too. This shortcode alone won't work since in this view "No pagination" option is selected in the "Pagination and Sliders Settings" section.

If you could share more specific information about the planned structure to split the results through the pagination, I'll be in a better position to guide you accordingly.

regards,
Waqar

#1383483

Hi,
Thanks for your valued support. I have updated the views as per your suggestions. Now, Let me clarify things one by one.
1. Hiding the State name without jobs:
Your tactic works for hiding the name of the State, will you please help me to hide the horizontal line <hr> when the state name is not there.
2. Pagination:
I want the pagination at a state-level view. For example 10 jobs at a time in a state (ignoring the job location).

I hope I can make you understand. If any further clarification required please ask me.

#1384233

Hi,

Thanks for the update.

1. Hiding the State name without jobs:

In your "states-view-grandparent" view, you can move the <hr> tag inside the div above and it will be hidden with the state too.

Screenshot: hidden link

2. Pagination:

Since the source of the job posts is not a single view, and they're coming from multiple views for places ( "places-belongs-state" ), pagination to job items with respect to states can't be directly applied.

To achieve paginated results like this, you'll first get the IDs of the relevant job posts, and then use those IDs in different views to actually output them on the front-end with pagination.

In summary, the steps will be as follows:

A). View: places-belongs-state

- In Query Filter, change the option to "The post with ID set by the shortcode attribute"
( screenshot: hidden link )

- From the "Loop Editor" section remove all the extra content, spaces and line-breaks:


[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-view name="jobs-belongs-places"]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-layout-end]

- From the "Output Editor" section remove the shortcode [wpv-filter-meta-html] and check the option "Disable the wrapping DIV around the View" just above this section.

B). View: Location wise Jobs

- From the "Loop Editor" section remove all the extra content, spaces, and line-breaks and only include [wpv-post-id], in the loop, since you'll need this view to only output the IDs of the relevant Job posts:


[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-post-id],</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-layout-end]

- From the "Output Editor" section remove the shortcode [wpv-filter-meta-html] and check the option "Disable the wrapping DIV around the View" just above this section.

As a result, you'll be able to call the view "places-belongs-state" with an ID of the state post, and it will return the IDs of the relevant job posts, in the comma-separated format.

Example:


[wpv-view name="places-belongs-state" wpvrelatedto="123"]

The above shortcode will return the IDs of all jobs, belonging to the state post with 123.

C). View: Location wise Jobs actual

- You'll create a new post view to show job posts and in the "Query Filter" add a post ID filter to include only posts which are included through shortcode attribute:
( ref: https://toolset.com/documentation/user-guides/filtering-views-query-by-post-id/ )

Example screenshot: hidden link

- In this view, you can set the pagination settings and design the output according to the requirement, as the final output would be generated using this view.

D). View: states-view-grandparent

- In this grandparent view "Loop Editor", you'll replace the view shortcode [wpv-view name="places-belongs-state"] with the shortcode to call the new view from step C.


[wpv-view name="slug-of-new-view" ids="[wpv-view name='places-belongs-state' wpvrelatedto='[wpv-post-id]']"]

Replace "slug-of-new-view" with the actual slug of your new view and note how the shortcode of the "places-belongs-state" view is used in this shortcode to pass on the required state post's ID and then it will return the IDs of the relevant job posts.
( ref: https://toolset.com/documentation/user-guides/passing-arguments-to-views/ )

I hope this helps and please let me know if any step is not clear.

regards,
Waqar

#1384857

Hi,
I followed your steps. But don't know why the view is not generating any results at all. One new view created with name "Location wise Jobs actual". Please check and let me know where it lacks. Thanks for your valued support.

#1385785

Hi,

I've made the following changes and the views are working as expected now:

1. No output was showing because in the view "states-view-grandparent" custom script existed, which would check for the existence of job post results through the div with class "jobs-wrap".

But in your view "Location wise Jobs actual" job results were not wrapped in such a div. I've replaced:


<div id="job">

With:


<div class="jobs-wrap jobs-wrap-[wpv-post-id]">

2. In the view "places-belongs-state", I've changed the query filter option from "The post with ID set by the shortcode attribute" to "The current post in the loop", so that we don't have to pass the ID through the shortcode attribute:

3. In the view "states-view-grandparent", I then updated the shortcode, from:


[wpv-view name="location-wise-jobs-actual" ids="[wpv-view name='places-belongs-state' wpvrelatedto='[wpv-post-id]']"]

To:


[wpv-view name="location-wise-jobs-actual" ids="[wpv-view name='places-belongs-state']"]

regards,
Waqar

#1385869

Well, first of all, a big thank you for your superb support. I am amazed to see how you guys are so talented. Hats off.

Now please clarify me certain things. For generating the view are we using four views? View ID: 19495, 17996, 17994 and 17991?
If yes why we are using 17996 (Location wise jobs) while that can be used by the new one (Location wise job actual)? If no then how we are filtering dates i.e jobs that are yet to expire?

Please help me to understand this thing.

#1386673

Hi,

Thanks for the update and glad that the job list is now showing as desired.

Using pagination was complex in this case because the source of the "job" posts was not a single view, but they were coming from multiple views for each "place" posts.

To clarify, if you were simply showing the list of all jobs, the list's structure from the view would look like this:

(1). Job A
(2). Job B
(3). Job C
(4). Job D
(5). Job E
(6). Job F

In that case, pagination would've worked directly to split the list into multiple pages.

However, in your usage case the structure was different:

1 - Place A
-- (1). Job A
-- (2). Job B

2 - Place B
-- (1). Job C
-- (2). Job D

3 - Place C
-- (1). Job E
-- (2). Job F

Notice how the available jobs are not at the same level and their ordering of results is changed and reset for every place (the number in brackets).

For this reason, we had to use two different views for Job posts:

1. The "Location wise Jobs" view gathers the IDs of the job posts which we need based on their source places.

2. The "Location wise Jobs actual" view just displays the list of job posts that were gathered by the view "Location wise Jobs".

And since the source of job lists in this second view ( "Location wise Jobs actual" ) is a single view and not multiple views ( like in "Location wise Jobs" ), the pagination works just fine with this view.

I hope this makes it more clear.

regards,
Waqar

#1386849

Superb. The way you resolve the issue without configuring PHP codes is really commendable. To be frank, nobody thinks this way. You'll be glad to learn that this State-Place-Job relationship was inducted into the system after your suggestions only.
When I was facing this pagination issue two of your support colleagues and one toolset contractor turned me down saying in this relationship model the pagination cannot be done and suggested me to change it.
Since I have been working in this structure for while, my database has grown big enough that it would be literally impossible for me to change the things. Thanks that you came to the scene.
One small help. Say I want to show 'No Jobs found' when there is no job in a particular state, rather than hiding the State name. How to do that?

P.S.: I want to share one private message with you. Will you please allow me?

#1387613

Hi,

I appreciate your kind words and very happy that my suggestions proved useful.

If you'll remove the custom script added in the "states-view-grandparent" view ( screenshot: hidden link ), the states without any jobs will show and the "No items found" message from the "Location wise Jobs actual" view will also show.
( screenshot: hidden link )

Note: it seems you've included the IDs of the selective states, in the shortcode for the view "states-view-grandparent" in the page "Toolset Test".
( screenshot: hidden link )

To include all states, you can remove those passed IDs from the shortcode:


[wpv-view name="states-view-grandparent"]

As requested, I've set your next reply as private and for a new question/concern, you're welcome to start a new ticket.

regards,
Waqar

#1387861

Thanks. All your tricks worked nicely and I am getting what I need.

Let me know, do you provide support outside the Toolset support page? If yes how to get it?

#1387955

Hi,

Thanks for the update and glad it works.

I won't be able to provide support outside the Toolset Forum, but, you're welcome to reach us anytime through this forum. All available supporters ( including myself ) will be happy to assist, accordingly.

regards,
Waqar