Saltar navegación

[Resuelto] Child should be able list posts of another child of a common parent.

This support ticket is created hace 4 años, 7 meses. 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: Africa/Casablanca (GMT+01:00)

Este tema contiene 12 respuestas, tiene 2 mensajes.

Última actualización por Jamal hace 4 años, 7 meses.

Asistido por: Jamal.

Autor
Mensajes
#1648327

Tell us what you are trying to do? I have a post called 'ISSUE' which has 2 children 'Articles' and 'Editorspeak'.. It's pretty straighforward to list all articles in ISSUE post as it's a parent child relationship.. but I want to list all Articles in Editorspeak where there's no relationship other than that they have a common parent.. how do I achieve this?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1648525

My issue is resolved now. Thank you!

It was a duplicate post so deleting this one

#1648585

Sorry I got confused.. with another ticket.. this one still needs to be resolved.. my bad.. sorry again.

Regards,
Alim

#1648851

Hello Alim and thank you for contacting the Toolset support.

This can be done by using an unassigned content template to switch the context from Editorspeak to Issue and then, you may reuse the view that displays Articles inside an ISSUE. Here is an example.
1. Create an unassigned content template that will hold the context of the "ISSUE" and insert it inside the Editorspeak template using the "item" attribute as follow:

[wpv-post-body view_template="my-new-content-template-to-hold-issue-context" item="@relationship-slug.parent"]

Notice that you will have to change "relationship-slug" with your actual relationship slug. Check this article https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/
2. Insert the view that displays an issue's articles inside this content template.

I hope this helps. Let me know if you have any questions.

#1649765
Screen Shot 2020-06-04 at 11.28.12 AM.png

Hi Jamal

I am completely lost..;-).. my apologies for not being able to understand this.. but could you guide me on this step by step?

If I create a template which is not assigned to any post, do I create view inside this?

If yes, I did try and I added a Query to the View which used 'Articles' for the Content Selection and in the QUERY field I chose the POST RELATIONSHIP... option and then the ISSUE-ARTICLE (screenshot attached)

But I can't seem to display the articles here as there's no CURRENT POST (it's not assigned to any post).. so I am confused on how will I get the image of the article in the ADD BLOCK..

And I am assuming, that after I do this, I have to put this template in the EDITORSPEAK template using the item attribute.. am I right?

Could you please help me with this? I am really struggling.

Regards,
Alim

#1649797
Screen Shot 2020-06-04 at 12.02.15 PM.png
Screen Shot 2020-06-04 at 12.00.46 PM.png
Screen Shot 2020-06-04 at 11.58.51 AM.png
Screen Shot 2020-06-04 at 12.05.53 PM.png

I've attempted something based on my understanding..

I created a VIEW 'articles-for-editorspeak' and added the relevant query and then used the BLOCK EDITOR and it saved a CONTENT TEMPLATE called 'Loop Item In Articles For Editorspeak'..

The view inside the content template was a classic paragraph editor with this short code
[types field="magazine-spread"][/types]

And then I used the EDITORSPEAK template and added a custom html block with this text as suggested by you..
[wpv-post-body view_template="articles-for-desktop" item="@issue.articles.child"]

Is the view_template name the name of the view or of the content template? I was not sure so I used the view slug.. in fact I didn't even know how to find the slug of the content template (if there is one)...

On check the Issues view I expected to see the images of the articles at the bottom of the page but there was no such view.. please advise what I am doing wrong..

Here's the link to the final page of Editorspeak

enlace oculto

And I've attached all the screenshots for the steps I've done..

Please do advise..

Regards,
Alim

#1649831
Screen Shot 2020-06-04 at 12.14.32 PM.png
Screen Shot 2020-06-04 at 12.14.23 PM.png

I fixed some errors that I had done..

The relationships was 'issue-article' and not 'issue.articles' so I fixed that and the view_template was 'articles-for-editorspeak' and not 'articles-for-desktop'..

so that code in the Editorspeak Template is this now
[wpv-post-body view_template="articles-for-editorspeak" item="@issue-article.child"]

But still not working..

enlace oculto

Regards,
Alim

#1649849
Screenshot 2020-06-04 12.21.23.png

I've added multiple shortcode blocks just to test if it's something I am doing wrong

so I've tried this

[wpv-post-body view_template="loop-items-in-articles-for-editorspeak" item="@issue-article.child"]
AND
[wpv-post-body view_template="articles-for-editorspeak" item="@issue-article.child"]
AND
[wpv-post-body view_template="articles-for-editorspeak" item="@issue-article.parent"]

None seem to work.. please advise.. (screenshot attached)

Regards,
Alim

#1650313

Hello Alim and my apologies for the late reply, I just started my shift an hour ago.

There are some issues with the shortcodes, I will try to describe how to fix them, but I'll need to explain the differences between a view and a content template. Please check our glossary page for more details:
- A content template is meant to display a single post(issue, article, post, page, portfolio, etc...).
If the content template is assigned to a custom post type, it will be used to display the single page for that custom post type. For example, if the content template is assigned to "Editorspeak", it will be used to render this page enlace oculto
If the content template is not assigned, it is meant to be used inside another content template or inside a view, in the loop for example.

- A view, on the other hand, is meant to query the database for a list of posts, that match a query filter and display them. The view has to be used inside a page, a content template, or another view.

Views and content templates can be added with different shortcodes, we can use either the name or the slug:
- The content template is added with the wpv-post-body shortcode and the view_template argument. The content template can inherit its context, the post that has to display, inside another content template or a view, or can take the context with the attribute item

[wpv-post-body view_template="my-content-template-slug-or-name"]

Or

[wpv-post-body view_template="my-content-template-slug-or-name" item="pass-the-context-here"]

You can see all possible attributes and attribute values in the following articles:
- https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-153372
- https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/

- The view is added with the wpv-view shortcode and the name attribute.

[wpv-view name="my-view-slug-or-name"]

https://toolset.com/documentation/user-guides/views/views-shortcodes/#vf-154377

This being said, I'll try to give some examples of the codes that can be used, but I cannot be sure unless I took a closer look at the relationships. I understood, that you are using two one-to-many relationships from the issue to both articles and Editorspeaks. If you are using many-to-many relationships, we may need additional steps.
1. Create an assigned content template for Editorspeak. Let's call it "Editorspeak Template".
2. Create an unassigned content template, that will hold the issue context, let's call it "Editorspeak parent Issue". Put a the wpv-post-title shortcode on it for testing.
3. Insert this template inside the first one:

[wpv-post-body view_template="Editorspeak parent Issue" item="@issue-editorspeak.parent"]

=> Check on the frontend if it is working at this stage.
4. Create a view that will display the articles of an issue. Or reuse the view that you are already using to display articles inside an issue.
5. Put this view inside the "Editorspeak parent Issue" template, below the title. The view should be configured to filter the query by the relationship the view where this post is shown, first option in your screenshot "Screen Shot 2020-06-04 at 11.28.12 AM.png"

[wpv-view name="my-view-to-display-articles-inside-parent-issue"]

=> Check on the frontend if it is working.

If you are having many-to-many relationships, you will need a first step that will use a view to display all the parent issues. And view loop should use the content template created in step(2).

I hope this makes sense. If not, please allow me temporary access to your website and I'll check your views further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1651159
Screen Shot 2020-06-05 at 10.58.30 AM.png
Screen Shot 2020-06-05 at 10.58.09 AM.png

Hi Jamal

I tried the below

1. Create an assigned content template for Editorspeak. Let's call it "Editorspeak Template".
2. Create an unassigned content template, that will hold the issue context, let's call it "Editorspeak parent Issue". Put a the wpv-post-title shortcode on it for testing.
3. Insert this template inside the first one:
[wpv-post-body view_template="Editorspeak parent Issue" item="@issue-editorspeak.parent"]
=> Check on the frontend if it is working at this stage.

But it didn't work.. I am attaching screenshots for you to show what exactly I did.. Please note that these changes are all on the production site.. so you won't find these in the staging site.

Regards,
Alim

#1651691

Hello Alim,

I followed the same exact steps and it worked for me. Check this editorspeak enlace oculto
Check this screenshot enlace oculto

You may need to deactivate caching for views while creating/testing, it can cache a wrong result and let you keep hitting the wall 🙂
Once your view is ok, you can activate caching back. Check this screenshot enlace oculto

Check this screenshot on how to set the query filter for the view, it has to look for related posts to the current post in the loop enlace oculto

I hope this helps. Let me know your feedback.

#1653587

My issue is resolved now. Thank you!

it has to look for related posts to the current post in the loop

I was not paying attention to this little detail..;-)... Instead of the 'CURRENT POST IN THE LOOP' I was selecting 'THE POST WHERE THIS VIEW IS SHOWN'..;-)..

I've figured it out now a bit.. hopefully I won't have to bother you again for these kind of parent-child relationships.. but it's kinda confusing right now for now.. thanks again for your patience.

Have a nice day..:-)..

Regards,
Alim

#1656227

Thank you, Alim for your feedback. It is all right, we are here to help and I am very glad that I was of help.

Please, feel free to open a new ticket whenever you have a question.

Best regards,
Jamal