Skip Navigation

[Resolved] using stored post id to view related posts

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the customer had stored some id in a custom field of another CPT but wanted to know if its possible to use Views to filter on his secondary view to show his Post Parent essentially.

Solution:

In this scenario we will be using Products and Beans where products has the custom field that stores the ID of the beans.

So essentially when you're on the bean's page you want to display the products?

In this case you will need to create a view for the product cpt and then add a filter for the custom field that has the bean id in it.

Then set that field so that the value is retrieved using a shortcode attribute. Next all you need to do is to add the view to the bean page and then pass the ID of the page into the view like this.

[wpv-view name='my-view' my_value='[wpv-post-id]']

This support ticket is created 6 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Anthony 6 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#604792

On a WooCommerce site selling coffee, I have a CPT with info about the different beans available. I have a custom field added to the WooCommerce Product post type that contains the post id for the particular Bean used by each Product. That's working fine for displaying a Product's related Bean info with a View that filters the Bean posts based on the custom field in the Product post.

What I also want to do is display what related products are available when viewing a single bean post, i.e. a View that is filtering the Products posts based on the custom field in each Product post being equal to the post id of the particular Bean post. Is there a way to do that?

#604876

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screen Shot 2018-01-09 at 3.09.11 PM.png

Hi Anthony,

Thank you for contacting our support forum.

So essentially when you're on the bean's page you want to display the products?

In this case you will need to create a view for the product cpt and then add a filter for the custom field that has the bean id in it.

Then set that field so that the value is retrieved using a shortcode attribute. See Screenshot. Next all you need to do is to add the view to the bean page and then pass the ID of the page into the view like this.

[wpv-view name='my-view' my_value='[wpv-post-id]']

Please try this and let me know if it helps.

Thanks,
Shane

#604887

Thanks, Shane. I was close, but a bit confused regarding the shortcode attribute, and your reply got me squared away.