Skip Navigation

[Resolved] List items in view from another CPT

This support ticket is created 5 years, 1 month 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 15 replies, has 2 voices.

Last updated by larryL 5 years ago.

Assisted by: Christian Cox.

Author
Posts
#1387195

I have a view for 'Projects' which displays all active projects. Within that list of projects I'd like to dislpay (in one column) the current 'defects' attached to each project. What I've done so far is created a seperate view and inserted in a column in the 'projects' view like this: [wpv-view name="number-of-project-defects-inline" cached="off"][/wpv-view]

In the defects view I tried something like this:

[wpv-conditional if="( $(wpcf-defect-select-project) eq '[wpv-post-title item="@defect-select-project.parent"]' )"][types field="defect-select-project"][/types][/wpv-conditional]

But all I get is the same 'defect ID' for every single project. How can I get it to display a list clickable post ID's in the column for each project?

Thanks!

#1387215

Within that list of projects I'd like to dislpay (in one column) the current 'defects' attached to each project
Hi, it depends on how you have set up your post relationships and custom fields. I'm not completely clear from the code you shared if defects are a separate post type, or if defects are a repeating post field on the project post type. This code indicates a defect is saved as a custom field somehow:

[types field="defect-select-project"][/types][

...but later you mentioned displaying a post ID for each Defect so I think the code above isn't quite right.

If Defects are a separate custom post type, no conditional is necessary in the View. You should create a post relationship to link Defects to Projects, probably a one-to-many relationship where Project is the parent and Defect is the child. That means the same Defect cannot belong to more than one Project. Then edit some Projects and associate them with some Defects in the post relationship editor.

Then in the View of Defects you have nested in the View of Projects, you would add a Query Filter based on post relationship, as related items of the current post in the loop. If you cannot see the Query Filter panel, scroll to the top right corner of the View editor screen and click "Screen Options" to reveal it.

In the Loop of the Defects View you can insert the wpv-post-id shortcode to display the numeric ID of each Defect. If you want to create a link to the single Defect post using the post ID as the text of the link, you can create a custom HTML link using the wpv-post-url shortcode and wpv-post-id shortcode so:

<a href="[wpv-post-url]">[wpv-post-id]</a>

Let me know if I've misunderstood what you're trying to accomplish and I'll take a closer look.

#1387227

I created the one to many relationship. But editing the project to 'include' some defects doesn't work for me. The defects would be added much later in the process. For example:

1 - a project is created.
2 - A module is added to the project
3 - a build is added to the module and associated to the project
4 - A test scenario is created and associated to all of the above
5 - Test Case(s) are created and associated to the Scenario and Project
6 - A defect is created and associated to the test case and project

A defect could also be created not related to a Test Case and associated to a project, module, build.

Hope this helps.

#1387243

But editing the project to 'include' some defects doesn't work for me. The defects would be added much later in the process.
6 - A defect is created and associated to the test case and project
It doesn't matter when or how the Defect is created or associated with a Project - the method to display Defects directly associated with a Project using post relationships is the same regardless. I was discussing the display of these Defects as I understood your setup and request, not the workflow to create relationships between the posts. That's a completely separate topic.

A defect could also be created not related to a Test Case and associated to a project, module, build.
Okay I understand these would all be separate post types: Projects, Scenarios, Test Cases, Modules, Builds, Defects. It also sounds like Defects could be related to any one or more of those post types, am I understanding correctly?

The process is different for showing Defects in all possible connections to a Project, depending on all the post relationships between these post types. I would need to understand more about the post relationships between all these post types in order to make a good recommendation here. What are the one-to-many relationships, what are the many-to-many relationships? How is everything connected? Am I missing any other important post types we need to consider here?

#1387489

I guess since the defect CPT already knows the realted project (the field is there as well) the filter can look at that too no?

IOW, for the view: show defects for X project: [defect id], [defect id], etc...

It would filter based upon the project name that it already knows.

#1388025

I guess since the defect CPT already knows the realted project (the field is there as well) the filter can look at that too no?
No, not "too", but "or," in the context of other post relationships. Let me elaborate on that a bit. You can set up a filter to display Defects directly related to a given Project. That works great in a View of Projects, because you can nest the Defects View so that each Project's Defects are displayed in the results. However, that same View's post relationship filter cannot also display Defects that are directly related to a given Build or a given Module related to that current Project, because this type of indirect relationship filtering is not possible in the current system without custom code. It is also not possible to create multiple post relationship filters for a View without custom code. Only one post relationship filter can be created and applied to each View in wp-admin.

So if you want to display the Defects directly related to each Project in a View, the process is as I described above in my comment beginning:
"If Defects are a separate custom post type..."

If you want to also display Defects indirectly related to each Project, that's considerably more complex because of the current system's limitations of post relationship filters.

I hope this helps clarify things, it's kind of a technical topic so I want to explain the nuances. If you'd like to see more practical examples of how this works, I encourage you to create a free account in our sandbox area at https://discover-wp.com so you can play around with these concepts. I can also collaborate with you there to help set up scenarios that explain what I'm talking about.

#1388205

We can either use the discover-wp (I have an account there) or my site which is not in production. Whatever is easier for you.

I'd like to make sure I understand what you are saying:

1 - Within a view (for Projects CPT) there is some sort of limiation on the ability of WordPress to understand the post relationships even though I've gone through the steps of 1) using the Post Reference field type (W/I the Defects DPT to relate the defect back to the associated Project, and 2) at your suggestion create the 1:many relationship between Projects & Defects.

2 - I cannot, for example, with the Projects view, insert a secondary 'Defects' View that contains a conditional field that looks at the post reference field to determine which defects are associated with the correct project.

I didn't mean to over-complicate this with bringing up other CPT's. I was simply trying to point out that there would be no situation where a user would enter a defect and then go back the project 'post' and add that defect to the project. This would have to happen through the relationship. Just like I know, based upon the relationship which module or build is tied to which project.

Thanks!

Larry

#1388285

1 - Within a view (for Projects CPT) there is some sort of limiation on the ability of WordPress to understand the post relationships
The limitation is not in WordPress, the limitation is in Views' implementation of Toolset's post relationship Query Filters. Only one post relationship filter is possible in a single View, unless you use custom code. Let's explore this on your development site, see below.

2 - I cannot, for example, with the Projects view, insert a secondary 'Defects' View that contains a conditional field that looks at the post reference field to determine which defects are associated with the correct project.
Not exactly. A "post reference field" in Toolset has a limited purpose, and I don't think it's appropriate in this case. If you plan to allow more than one Defect to be associated with one Project, a post reference field will not allow you to accomplish that because repeating post reference fields are not supported. This means you would have to create a finite number of post reference fields to be applied to all Project posts. Your Users you could never add more than that number of Defects, and there might be a lot of empty Defect fields...not really practical, as I understand the requirements of your site.

Instead, you will create a post relationship between Projects and Defects without using a post reference field. Once that post relationship setup is established, you can certainly create a Projects View and insert a nested Defects View that contains a single post relationship filter, such that the Defects displayed with each Project in the outer View are only those directly related to that Project. That's no problem.

The limitation I was referring to would occur if Defects were also directly related to Modules, and Modules were directly related to Projects. If Defect A was directly related to Module A, and Module A was directly related to Project A, but Defect A and Project A were not directly related, then Defect A would not appear in the nested View for Project A because the post relationship filter is only configured to detect direct relationships between Projects and Defects.

I think this will become more clear when we get started and you see the workflows possible for linking two posts in Toolset's post relationships, and we discuss how you plan for your site Users to work. If you already have a development environment setup, let's work there. Please create a User for me with admin privileges and provide those login credentials here in the private reply fields.

#1393447
Screen Shot 2019-11-27 at 10.11.28 AM.png

So I can't use the post reference field until the relationship has been established first?
A post reference field establishes a specific post relationship. That relationship does not need to be created separately in Toolset > Relationships, the relationship is inherent to the post reference field itself. I can see that you have already established links between several Projects and Defects using a post reference field on the Defect post type, so I have updated the Project Dashboard View to show you how this reference can be used in a nested View of Defects. I have added a post relationship filter and chosen the Select Defect Project relationship - this is the name of the relationship inherent to the Select Defect Project reference field. I have removed "Project" from the content selection area, because this View should only display Defects. I've also modified the loop template to display the link to the Defect post. You can modify that or remove the link if you just want to show the number of related posts.

Now for each Project row, you can see a list of related Defects. See the screenshot here.

#1393635

Fantastic! Thank you.

One more question.

If I want to narrow it down to 'My Defects' how can I only show the defects of the logged in user?

#1393647

the defects of the logged-in user
You mean the Defect posts where the current logged-in user is also the Defect post author? If so, then you will edit the Defects View and add a Query Filter to filter by post author.

https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

If you cannot see the Query Filter panel in the View editor, scroll to the top right corner and click "Screen Options". You can activate the Query Filter panel here. Click "Add a Filter" and select "post author". Configure the filter settings so that the author is the same as the current logged in User.

#1393665

Can you think of a reason why the Title of a Project would show up as CRED Auto Draft 6ef5bcf7acfa3846efa791b78c28802c?

#1393675

Yes, if a Project post was created in a Toolset Form that does not include a standard post title field, the autodraft hash would be used as the default post title. I can see here your Form does not include the standard post title field, so I assume this is what happened: hidden link

I normally recommend using the standard post title field to hold the post name, instead of a separate custom field for the Project name. You can add the standard post title field back in the drag and drop Form editor and remove the Project Name custom field from the Form editor if you would prefer to use this solution.

On the other hand if you want to use a custom field to store the Project name for some other reason, that's fine. You can copy the Project Name custom field into the post title field automatically with some custom code. Another ticket in the forum discusses the solution here: https://toolset.com/forums/topic/post-title-set-to-auto-draft/

#1393693

That worked great. BTW, in the View that displays the projects/Defects. I cannot differentiate what changes you made in the loop IOW, Did you modify a different view than what I was using before? I see the filters, but I don't see the two different items in the loop 1) show the count of defects, 2) show the list of defects.

#1393751
Screen Shot 2019-11-27 at 1.59.51 PM.png
Screen Shot 2019-11-27 at 2.00.02 PM.png

so I have updated the Project Dashboard View to show you how this reference can be used in a nested View of Defects.
Sorry, I had this backwards and I think it caused some confusion. I updated the Number of Project Defects - Inline View to show you how it can be used nested in the Project Dashboard View.

I'm attaching screenshots of the changes I made in the defects inline View. You had a lot of wpv-conditional code in the loop and the template that was not necessary, as you mentioned at the beginning of this ticket:

[wpv-conditional if="( $(wpcf-defect-select-project) eq '[wpv-post-title item="@defect-select-project.parent"]' )"][types field="defect-select-project"][/types][/wpv-conditional]

The Query Filter section is filtering the Defects by post relationship and by post author, so you don't need additional conditionals in the loop or template to handle those things.