Skip Navigation

[Resolved] displaying related posts based on current posts field value

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

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by jozsefG 4 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1249071

Hello

I have two cpts, TRAININGS and TRAINING EVENTS. These are related in a one-to-many relationship. In TRAINING EVENTS single I want to insert a view of those events that are held in the same city, CITY being a custom field of TRAINING EVENTS. So in the query filter I should specify that CITY equals to constant CITY OF CURRENT POST. But how do I specify city of current post?

#1249083
#1249271

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Jozsef,

Thank you for waiting.

To pass on the name of the current post's City to the view, you can use a shortcode attribute.
( ref: https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes )

1. In the "Query Filter" section of your view, you can include a custom field filter for the city field, that is a "String" and is "equal to" the "Shortcode attribute" named "city".
Example Screenshot: hidden link

2. Next, you can update your view's shortcode, to include this new attribute "city" and the current post's city value like this:

Before:


[wpv-view name="slug-of-the-view"]

After:


[wpv-view name="slug-of-the-view" city="[types field='city-field-slug'][/types]"]

Note: You'll replace the "slug-of-the-view" and "city-field-slug" to match the values from your actual view and the custom field.

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

regards,
Waqar

#1249313

It seems that I encountered again the shortcode in shortcode problem. If I remember well somewhere I had problem with this some months ago.

hidden link

Look at the end of the long sidebar on the left. It appears [/types] at the end of it and list every event.

[wpv-view name="traininguri-planificate-alte-trainiguri-in-oras" city="[types field='city'][/types]"]
#1249315

I re-read my older support threads. The problem is that in Divi library items you cannot use shortcode within shortcode because the inner shortcode doesn't get interperted. In my case the city attribute. It was simpler for me to use divi libraries and assign them as templates in CPT layout injector than using the same finctionality in Toolset. But I try it now the toolset-only way for this single. I get back with the result.

But this surely is an annoying bug, and I don't know if it's Divi's or Toolset's. Do you know about this?

#1249321

Yes, this way it is working now.

#1249431

I have another related view that I thought it will be easy but it is not working.

I want to show all the TRAINING EVENTS under the same TRAINING parent.

I tried just setting up the relationship filter to show related posts by the relationships. This shows nothing.

I also tried the shortcode version where I added:

[wpv-view name="traininguri-planificate-alte-ocazii" parent="@training-training-planificat.parent"]

This shows every post regardless of parent.

#1250625

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Jozsef,

Thanks for writing back and for sharing the update.

If shortcodes within shortcodes are working through Toolset, but not through the DIVI's library items, this suggests that this is a limitation at DIVI builder's end. You can report this to their official support team for possible improvement or workaround.

Using parent="@training-training-planificat.parent" attribute in the view's shortcode, shows that we need some information from the parent in the relationship, but doesn't specify exactly which info is needed.

Since in this case, we need the parent's ID, it will need to be included in a "wpv-post-id" shortcode.
( ref: https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153366 )

Old shortcode:


[wpv-view name="traininguri-planificate-alte-ocazii" parent="@training-training-planificat.parent"]

Updated shortcode:


[wpv-view name="traininguri-planificate-alte-ocazii" parent="[wpv-post-id item='@training-training-planificat.parent']"]

regards,
Waqar

#1250639

It is working perfectly. Thank you very much Waqar!!!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.