Skip Navigation

[Resolved] REOPEN Beta: Many to Many Relationships – Display Views based on Custom Field

This support ticket is created 6 years, 7 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 12 replies, has 2 voices.

Last updated by Nigel 6 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#720019

This ticket is in reference to: https://toolset.com/forums/topic/many-to-many-relationships-display-view-based-on-relationship-custom-fields/

I know it has been a while... but I thought I would reach out to see if any of the new beta releases support this yet AND/OR the final release is planned to have this feature.

As a reminder, the issue is the current stable release allows filtering views by custom field [of intermediary CPT for many-to-many relations] as detailed here: https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

To clarify, I am trying to display a filtered view. There are two methods I'm aware of, but neither seem to work yet in the beta releases.

Method #1 = Modify the actual VIEW, as shown here:
hidden link (source: https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/ )

Method #2 = Create a general view and then try to filter it based on a shortcode parameter, like below:
[wpv-view name="recommended-products" order="asc" wpcf-relationshiptype="authored"]

Is this going to be resolved at some point in the beta or full release?
Any kind of ETA for full stable release of the new version?
Is there any current workaround?

#723548

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

We will be publishing release candidates for the "final" versions today or tomorrow. QA testing is likely to take a couple of weeks, when, all being well, the stable versions themselves will (finally!) be published.

Then work can being on features that didn't make the cut for the initial release. Filtering by post relationship fields or by fields of related posts is the most important such feature, and will be prioritised.

In the meantime, if you have many-to-many relationships on a site with the stable plugins which are actually comprised of two one-to-many relationships using an intermediary post type, that is how they will be converted in the new versions and the filtering will continue to work as before (because your View to display related posts actually queries the intermediate post type and so can filter by its fields).

Until the filtering by relationship fields or fields of related posts is added, the only way to achieve this with the update is to do it the same was as now: create two one-to-many relationships with a shared intermediate post type, then create a View that queries the intermediate post type but displays fields from one of the parents. There isn't any alternative with actual many-to-many relationships at the moment.

I'm sorry that this means waiting longer for the full feature. We are almost at the finishing line for the main project, and this feature will be added shortly thereafter.

#743561

I'm really puzzled by your company lately.

Why would you release a new full production version the doesn't include core and crucial features of the previous version... especially when you committed to customers that the new version would have all previous features.

This doesn't make any sense 🙁

#743584

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, you'll have to forgive me, there was some mis-communication with the developers about what was included and what will be added.

Filtering a View that queries one post type by fields of related posts is the missing part of the jigsaw that will be added in an update.

Filtering by fields of the intermediate post type (i.e. filtering by the relationship fields) *is* included in the release candidates just published.

You simply need to—much like before—create a View that queries the intermediate post type, then include a filter for the post relationship that this intermediate post type belongs to, and include filter controls for the fields belonging to this intermediate post type.

In the Loop Output section, when you insert shortcodes to display fields, you can specify whether the post the fields should come from should be the current post (the intermediate post) or either of the posts connected in the relationship.

Again, sorry for confusion.

I tried it myself earlier and it was fairly straightforward, but if you update to the latest betas and have problems, let me know.

#743695

What's the proper way to delete everything related to toolset so I can "downgrade" from the beta to current stable?

Also... I am confused about something important. If the final new version RC was released and the new version production release will NOT have features in the current production... what happens when the new production version is released and auto-upgrade from the current product version?... won't that completely break websites?

#745443

I have tried everything and cannot seem to make it happen.

CPT #1: People
CPT #2: Products (most of these are books)
CPT #3: People Products (Many to Many)... with a custom field "Relationship Type" that is a dropdown with options "Authored" and "Recommends" and "About" (i.e. The related product is [a book] about the person that he/she did not author or recommend),

I have a content template for a "Person" profile where I want to show all the Products the Person recommends.

Method #1: View with Custom Field Filter Filter: Created a view ("Recommended Products") with a filter like below. Does not work.

View "Recommended Products":
Filter by post relationship or repeatable fields group owner:
Select posts in a People Products relationship that are related to the Post where this View is shown.

Custom field filter :
Select items with field: Relationship Type is a string equal to recommends

Shortcode: [wpv-view name="recommended-products"]

Method #2: "General View" with "Filter" as Parameter Shortcode: Created a view ("Recommended Products") with NO filter and filter with the shortcode. Does not work.

View "Recommended Products":
Select posts in a People Products relationship that are related to the Post where this View is shown.

Shortcode: [wpv-view name="recommended-products" wpcf-relationshiptype="recommends"]

---

Both result in "No items found"

The only thing I can consistently get to happen is showing ALL the Products associated with a Person (with no filters).

Which of these are supposed to work in the newly published RC?

What am I missing?

#746738

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

"If the final new version RC was released and the new version production release will NOT have features in the current production" - that's not the case. There are only added features, no missing ones. Even with filtering by intermediate post fields this was still possible the old way, I had mistakenly thought you couldn't do it yet with the new M2M relationships (rather than two one-2-M relationships), but you can.

To display related products *without* filtering you would create a View to display products and add a Post Relationship Query Filter "Select posts in a People-Products relationship, that are related to the Post where this View is shown.".

So that would show Products related to the Person where this View was inserted.

But, to display related products *with* filtering by the "Relationship Type" relationship field you must create a View where the Content Selection is your People-Products intermediate post type.

This allows you to add filters by its fields.

So you will need two filters.

The first is to connect it to the related Person, i.e. "Select posts in a People-Products relationship, that are related to the Post where this View is shown."

The second is the Custom Field Query Filter for your relationship field "Relationship Type", i.e. "Select items with field: Relationship Type is a string equal to Recommended" or similar.

Insert this View onto your People template and you will see the recommended products for that person.

#751182
2018-04-27_10-18-18_toolset4.jpg
2018-04-27_10-18-18_toolset3.jpg
2018-04-27_10-17-43_toolset_relationship.jpg
2018-04-27_10-08-50_toolset.jpg

Thanks for the clarification.
Are there any documentation + examples published? I

Isn't the "correct way" you described = Method #1 example:

Method #1: View with Custom Field Filter Filter: Created a view ("Recommended Products") with a filter like below. Does not work.

View "Recommended Products":
Filter by post relationship or repeatable fields group owner:
Select posts in a People Products relationship that are related to the Post where this View is shown.

Custom field filter :
Select items with field: Relationship Type is a string equal to recommends

Shortcode [wpv-view name="recommended-products"] inserted on a Person Page, with the goal of seeing related products that are recommended
----------
See screenshots please.

When I do the above and insert a view into a Person page, it returns no results.

#766179

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The difference between what you describe above and what I proposed is "you must create a View where the Content Selection is your People-Products intermediate post type"

It looks like your intermediate post type isn't showing up in the Content Selection section of your View, meaning that when creating the relationship you chose not to make it public.

Go to Toolset > Post Types and edit the person-product intermediate post type and change its status from draft to publish. You should then see it available in the Content Selection of your View.

You will then be able to filter by its fields.

#768623

Just did that... and no change to the view output

#768772

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Perhaps I should take a look at your site because it works fine on my test site and there must be some minor detail that isn't set correctly, which I can perhaps spot if I look in person.

I have marked your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete.

Can you also confirm where you are adding the View?

#771181

I figured it out!!!

The problem was not in the View, but in the template! Apparently, the syntax has changed, and the problem was here:
Old:
[wpv-post-featured-image size="custom" height="250" id="$book"]
[wpv-post-link id="$book"]

New:
[wpv-post-featured-image size="custom" height="250" item="@person-product.child"]
[wpv-post-link item="@person-product.child"]

-----
However, I a couple related clarifications...

-------
Question #1 - Just so I understand correctly, the ability to have a view filtered by shortcode paramters, is NOT possible in the new version... correct? (e.g.: [wpv-view name="recommended" wpcf-relationshiptype="authored"]

Question #2: Are there any documentation + somewhat complex examples published (e.g. the bands / appearances / venue example for the current stable version) related to the new version?

#776300

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, sorry about that.

If you migrate an existing site with relationships the old syntax should work I believe, but I'm not sure exactly what the history of your site is. If you create new relationships then the new syntax is required.

The available documentation with examples is here: https://toolset.com/documentation/post-relationships/

In the new version you can still use shortcode parameters for Views filters.

If you edit a View and insert a Query Filter you can choose where the value comes from, including specifying that it comes from a shortcode attribute. The attribute name in the filter must correspond with the attribute name added to the wpv-view shortcode, and if it is not working that it the most likely cause of the problem.

The documentation for this is still applicable: https://toolset.com/documentation/user-guides/passing-arguments-to-views/