Skip Navigation

[Resolved] Display intermediary post data from a specific post

This support ticket is created 4 years, 2 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: Africa/Casablanca (GMT+01:00)

Tagged: 

This topic contains 13 replies, has 2 voices.

Last updated by Jamal 4 years, 2 months ago.

Assisted by: Jamal.

Author
Posts
#2016023

I have a many-to-many relationship between CPT Posts Shows and Venues - I have an intermediary CPT set up which lists the show times and other info. I have a View Set up for Posts (Shows) and one set up for Venues - all straightforward.
However, I want to display the intermediary data elsewhere on the site.

I know I can display this data anywhwere by setting up a WYSIWYG custom field and using a Toolset Shortcode
I want to do the following:
I want to pull the intermediary data for a SPECIFIC venue on the page (so that I can display that entry specifically elsewhere by use of a shortcode)

What I am having trouble with:

Using .association I cannot display the correct intermediary data for the venue in question from that post. It just takes the first listing. I thought this would be possible by linking to the venue ID on the the intermediary data. I have tried a multitude of ways but to no avail.

So Show 1 will have Wembley Arena listed as a venue, I want to be able to pull the intermediary data for Wembley Arena specifically for that show.

Show 2 will also have Wembley Arena listed as a venue and I would like to pull the intermediary data for Wembley Area for that show specifically.

.intermediary/parent/child don't work. Only .association shows any data.
So my question is as follows:
If the code to pull the intermediary data from the page into the WYSIWYG is as follows:
[types field="date" item='@post-venue.association'][/types]
How would I specifically show that for the Venue with Post ID '1234' in the list?

#2016045

Hi there, I understand this has been moved to an email ticket. I just want to make sure this does not appear on the forum please.
Thanks, Chantal

#2016053

Hello and thank you for contacting the Toolset support.

Indeed, I did not update my chat availability before taking the lunch break. My apologies for the inconvenience.

Keep in mind that a shortcode needs to know what is its context, what is the post meant to display. Then, using the item attribute your can display data from a related post, or from a different post. When you choose to display data from a related post, the shortcode needs to know the original context to calculate the related post.

In this case, the original context is the page where this shortcode is used. We can switch contexts by using a different/new content template. We'll pass the original context to it using the item attribute. In this case, it would be the venue post. Like this:

[wpv-post-body view_template="name or slug of the new content template" item="1234"]

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153372
Then, we can display the data inside of this content template from the related post:

[types field="date" item='@post-venue.association'][/types]

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

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

#2016345

Hi Jamal,

It didn't work. I was getting the same result as before - ie a result but not the correct value.

Before I send over further information and screenshots can you assure me that this thread is completely private? I don't want this on the forum.

Thanks,
Chantal

#2016371

Hi Jamal, unfortunately it didn't work. I got the same result as before ie a result from the intermediary list but not the correct value.

Before I send over further information and screenshots, can you please assure me that is thread is completely private? I don't want this on the forum.

Thanks,
Chantal

#2016875

This thread is public, but the links and the screenshots inside of it will be private. Only you and the Toolset team can see them.

Please allow me temporary access to your website to check this further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#2026143

Thank you Chantal for these details, but I still need to know what would you want to display and where?

I understood that you want to display the intermediary posts for a specific venue somewhere else using a shortcode, right?

Can you tell me where do you want to display what? And what views/content templates/ have you created for it so far?
I am setting your next reply to be private to let you share URLs safely. You can enter dummy credentials or enter the same credentials in the form.

#2026279

Can you enable the private reply again please?

#2026393

Sure.

#2026473

Hello Chantal, Thank you for this, it gives me some insights into what you want to build. However, I am afraid, it is not very clear for me.

What would help is including URLs, because URLs, help me better to get into the context. With a URL, I can know if it is a page, a post. I can know if a content template or a view is involved. It is also helpful to break the text into smaller steps.

So, can you tell me in terms of URLs what would you display and where? For example:
- I want to display in this page (URL of the page, I can get the post, post type, etc. from here)
- In this section(Screenshot, or URL in the backend of the view that is displayed on that section).
- This information(Screenshot, and URL in the backend, where I can see this information).

In the meantime, I would like to say the following:
The fields from your screenshot "View full size in another window" are actually fields from the parent post hidden link

And you use shortcodes insides of it to pull information from the intermediary post, right? That's not the correct form, intermediary posts are ALWAYS retrieved using a view. Because they are expected to be a list of intermediary posts, not one.
You can use the item attribute inside the intermediary post to get data from the parent or child posts, because it is expected to be only one post(one parent, and one child). Does it make sense?

Please let me know an example of what you want to achieve and what you have created so far to help you further. Please add as many URLs as possible. And add as many screenshots as possible. And break your description into small steps. I am setting your next reply to be private too. The links that I have shared will remain private to any visitor to our forum.

#2027265

Thank you, I see the picture better now, but I still need to know what the "Content Box" field is meant for? I tried to find out where it is being used, but I did not.

Here what I understood so far:
You want to display data from the intermediary post of a specific parent(The Addams Family) and a specific child(BATH, Theatre Royal Bath) in a regular WordPress page(/musicals-in-bath/), right?
This how you tried so far:
- Displaying a list of posts, with Elementor, in the "/musicals-in-bath/" page using a 3rd party shortcode "wp_show_posts".
- "The Addams Familly" post uses an Elementor template(Tour schedule) in the post content.
- "Tour schedule" template, uses "Show Schedule" view.

I still don't understand the use of the "Bath Content Box" custom field, especially, because it uses another view "bath-theatre-royal-view". Where this field is used?

If I understood well(getting the intermediary post for specific parent and specific), I would say, that's not possible without some custom coding.
Toolset, currently, does not allow filtering a view by two relationships. Because the intermediary posts have, actually, two one-to-many relationships, one with the parent and one with the child. We plan to support multiple relationship filters in an upcoming release, maybe next year.

To get the intermediary post, we need to intersect two groups of posts:
- Intermediary posts related to the parent post. Let's call them (Parent_Posts)
- Intermediary posts related to the child post. Let's call them (Child_Posts)

There are two possible solutions to get the intermediary post for a specific parent and child:
- Hooking into the view's query and change it, using the wpv_filter_query filter and the toolset_get_related_posts.
- Using a nested view as a view shortcode. Something like:

[wpv-view name="my-view-to-get-intermediary" parent="[shortcode to get parent id]" child=[shortcode to get related posts for child post]]

For the second solution, the view's output needs to be cleaned up from HTML markup, and multiple lines so it just returns the Child_Posts IDs separated by comma (,). Check the custom code in the summary of this ticket https://toolset.com/forums/topic/matching-view/

This view needs to query intermediary post type, and have two query filters:
- Filter on the relationship related to a parent passed by the shortcode attribute "parent". (The view will look for Parent_Posts)
- Filter on posts IDs in the list passed by the shortcode attribute "child". (We pass ChildPosts here to let the view do the intersection with Parent_Posts)
Does it make sense?

This being said, I just need to know what the "Bath Content Box" filed is? What do you want to use it for? And where do you intend to use it?

As a side question, how much do you expect to have of the posts and the venues(few, dozens, hunderds)?

#2027329

Hi Jamal, just ignore the Views that I set up because I don't know what I am doing there. You asked me what I had done so far so I tried to do something and it didn't work. Just delete them, I am interested in your solution.

I have around 80 venues, and 40 posts

The content box is not really not important here. Each Venue will have a Content Box, whatever intermediary data pulled in here will be displayed elsewhere using a shortcode. In the example I gave you, the intermediary data for Bath is here, so using a shortcode I displayed this data from the content box on the Bath page I created (but the example I gave you wasn't working because the View etc is in correct)

Your second solution... can we put it to the test?
[wpv-view name="my-view-to-get-intermediary" parent="[shortcode to get parent id]" child=[shortcode to get related posts for child post]]

After reading your explanation I am still not sure what to put as the query filter, could you please set it up for me so I can test it?
And if the parent id is 2528 and the child id is 5067 how would this be written in the above example.

Thanks for your help.

#2027725

Hi Jamal, can you please enable the private reply? Thank you.

#2030829

I worked on an example today, and I think that I got it working. Check this screenshot hidden link

Because of some limitations, and because it will need custom code, I used a different approach. These are the limitations:
- You are using the "wp_show_posts" shortcode to display the 3 posts. This way, we can pass the child's post to the views that we will use. You need to use a Toolset view instead of "wp_show_posts".
- We can't have 3 levels of nested values such as:

[wpv-view name="view1" parent="[wpv-post-id]" child=[wpv-view name="view2" parent="[wpv-attribute ="child"]" ]]

So, here how I implemented it:
1. Create a view that will display the posts hidden link
The view does not have any filters. It displays the posts, and we need to use it instead of the "wp_show_posts" to pass the child post(BATH venue) ID as an attribute

[wpv-view name="ts-posts" child="5067"]

2. Create a view to display intermediary posts related to a post from a shortcode attribute. Check this screenshot hidden link
hidden link
3. Custom code to change the view's query arguments. The code will get search for the intermediary post of the child post, and do the intersection:

add_filter( 'wpv_filter_query', 'get_intermediary_posts_by_subject', 30, 3 );
function get_intermediary_posts_by_subject( $query_args, $view_settings, $view_id ) {
	// Execute this code only for my view id(7273)
	if ( $view_id == 7273 ) {
		// get the child post ID from the shortcode attribute of the parent view
		$child_id = (int) do_shortcode( '[wpv-attribute name="child"]' );
		// return the query arguments for an incorrect post ID
		if ( !( $child_id > 0 ) ) return $query_args;
		// get the intermediary posts from the child post
		$intermediary_posts = toolset_get_related_posts( $child_id, 'post-venue', array(
			'query_by_role' => 'child',
			'limi' => -1,
			'role_to_return' => 'intermediary'
		));
		// Perform the intersection with the posts returned by the view(from parent post)
		$query_args['post__in'] = array_intersect( $intermediary_posts, $query_args['post__in'] );
	}

	// return the query arguments
	return $query_args;
}

4. Use the view inside the loop of the first view(step 1) and pass the child and parent IDs:

[wpv-view name="ts-intermediary-post-for-a-post-venue" parent="[wpv-post-id]" child="[wpv-attribute name='child']"]

You can see that we get the parent from the current post in the loop using the wpv-post-id shortcode. And we get the child from the view's shortcode attribute "child" using the wpv-attribute shortcode.
5. Use the view inside the page(Elementor) and pass the child post(venue) ID to it:

[wpv-view name="ts-posts" child="5067"]

Please note that steps(2,3) may be enough, and will allow us to use this directly:

[wpv-view name="ts-intermediary-post-for-a-post-venue" parent="2528" child="5067"]

This way, you can build the page using Elementor(3columns) and display each post without using a view(steps 1,4,5).

Regarding the content box field, I am sorry, but still don't understand what is meant for. But, I don't think that it is a good practice to use a custom field as a template or design for displaying. Custom fields are meant to store data, content templates are mean for the "how to display the data".

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