Skip Navigation

[Resolved] Parent post connections

This thread is resolved. Here is a description of the problem and solution.

Problem:

Display parent page information.

Solution:

You can try to setup the item attribute as:
item='$parent'.

for example, in the child page, you can display it's parent page field "postadress" value with below shortcode:

[types field='postadress' item='$parent'][/types]

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/

This support ticket is created 4 years, 9 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
- 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)

This topic contains 8 replies, has 2 voices.

Last updated by matsF 4 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1555067

Hi,
I have a site with a standard template for pages built as a Toolset Content Template, it's called "Template for Pages new". (I'm using Beaver builder for the design.) I'm picking custom fields and relationships fields from the page, including a couple of listings/views, and have managed to display them correctly on the frontend. I put them in a column on the right with the intention to make it look like a information sidebar.

Example: hidden link

Now, my client, wants me to add sub/child pages to some of the pages. So now the same information has to be moved to the subpages. The parent page will not have the info anymore on the frontend, but it still has to be entered on the same (parent) page and be displayed equally on the sub/child pages.

Example parent page: hidden link
Example sub/child page: hidden link

I have created a new Content Template called "Template for Pages Parent" and tried to modify the shortcodes, but as I understand it you need som kind of grandparent connection to make it work. I checked out this link, https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/, but I didn't really get it. I tried that small content template for the extra parent level, but never succeeded.

There are three different shortcodes I'd like help with:

1. A field in a reference field in the CPT Platserinfo/Platsinfo.
[types field='postadress' item='@platsinfo.parent'][/types]

2. A view called "Events platser" showing Events filtered by Platserinfo/Platsinfo reference field.
[wpv-view name="events-platser" wpvrelatedto="[wpv-post-id item="@platsinfo.parent"]"]

3. A view called Kontaktpersoner filtered by post relationship Kontaktpersoner (Pages<->Personer)
[wpv-view name="kontaktpersoner"]

Containing the content template fields:
[types field='ansvarsomrade' item='@kontaktperson.intermediary'][/types]
[wpv-post-title], [types field='befattning' output='raw' ][/types]
[types field='telefonnr' output='raw' ][/types]
[types field='epost'][/types]

I started to target my shortcodes with the corresponding parent page id as a solution, but didn't make it on shortcode #3. But with that approach I have to make a new template for each group of child pages. Better to do it properly.

Hope you can help me out!

Regards Mats

#1555793

Hello,

I assume we are talking about WordPress built-in parent/child page feature, if it is, you can try to setup the item attribute as:
item='$parent', for example, in the child page, you can display it's parent page field "postadress" value with below shortcode:
[types field='postadress' item='$parent'][/types]

See our document:
https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/
$parent is used to retrieve data from a hierarchical parent if the current post is a type of hierarchical post such as a page. If the reference does not match an existing post, the data from the current post will be returned.

If you are going to display multipl custom fields and views of parent page, you can put those shortcodes into a content template, then pass item='$parent' attribute in the content template shortcode [wpv-post-body], for example:
1) Create content template "my-parent-page-info", with the codes you mentioned above:

...
[types field='ansvarsomrade' item='@kontaktperson.intermediary'][/types]
[wpv-post-title], [types field='befattning' output='raw' ][/types]
[types field='telefonnr' output='raw' ][/types]
[types field='epost'][/types]
...

You can add more shortcodes into above content template

2) In the single child page, display above content template with below shortcode:
[wpv-post-body view_template="my-parent-page-info" item='$parent']

#1556161
grandparent problem.jpg

Hi Luo,
thanks for the clarification regarding the content template approach, I must have switched it around when I tried it.
I got my first example to work, it makes sense to me now, but let me just check that I understand what you mean when it comes to views, since I got example 2 to work but not the 3rd.
So what you mean is that you take the view shortcode from the page template and put it in a content template? I put this one from my second example in a content template with the slug parent-page-events-platser:

[wpv-view name="events-platser" wpvrelatedto="[wpv-post-id item="@platsinfo.parent"]"]

I put it in a content template with the slug parent-page-events-platser and that template in the child page template with the shortcode: [wpv-post-body view_template="parent-page-events-platser" item='$parent']

It worked fine, but not my 3rd example. The one with the many-to-many-relationship connection (and the intermediary field connection in the view content template).
I'm not sure how to filter the view Kontaktpersoner now. The setting in the previous "no parent"-approach doesn't seem to work. (See image.)
I'd very much appreciate if you could help med here. I have prepared a login for you.

Regards Mats

#1556891

For the 3rd problem, you can try with content template too.

You can try these:
1) Edit the post view "events-platser", switch to option: The current post in the loop
see your screenshot:
https://toolset.com/wp-content/uploads/2020/03/1556161-grandparent_problem.jpg

2) Create/edit the content template "my-parent-page-info", display above view's shortcode directly, for example:
[wpv-view name="events-platser"]

3) In the single child page, display above content template with below shortcode:
[wpv-post-body view_template="my-parent-page-info" item='$parent']

#1557083

Hi, Luo,
Seems like you swiched #2 and #3. The view "Events platser" displays the Events post type (my 2nd example that seems to be working). My 3rd example the view Kontaktpersoner (contacts) displays the Personer post type (persons). I tried to change the filtering according to your suggestion on the view Kontaktpersoner and it seems to be working.

Thanks a lot!

/Mats

#1557089

I am not sure how and where do you want to display the post view you mentioned above, please provide a test site with the same problem, fill below private message with credentials, also point out the problem page URL and view URL, I need to test it in a live website. Thanks

#1557157

Hi Luo,
Sorry, for being unclear. A misunderstanding. Everything seems to be working at the moment. And hopefully we can end this thread. You had just switched the two examples and views, and first it made me a little confused. I shouldn't have mentioned it. My fault.

Thanks again for your fast feedback.
/Mats

#1559311

Sorry for the misunderstandings, since I am not sure your website settings, those examples are only examples, you will need to customize them according to your website settings.

Please let me know if you need more assistance for it, feel free to open new threads if there is other new questions.

#1563503

My issue is resolved now. Thank you!