Skip Navigation

[Resolved] Two Custom post type relationship

This support ticket is created 3 years, 5 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
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)

Author
Posts
#1853415

Tell us what you are trying to do?
I have two differrent custom post type 'Seller' and 'paidviewers'. In the paidviewer I have a custom field which stores the the ID of the Seller custom post type.I am want to create view display all the post items and with the post item an if conditional to match the Seller Id with paidviewer custom field Seller_id. What would be the best way to achieve either custom function or how can I create relationship within two post type .

Is there any documentation that you are following?
no
Is there a similar example that we can see?
no

What is the link to your site?
hidden link

#1853661
query-filter.png

Hello, if you want to use a custom field to link two posts, this approach will not be integrated with Toolset's latest Post Relationships feature. Toolset's latest Post Relationships feature uses custom database tables to manage post relationships, not custom field values. This new relationships system allows many-to-many relationships with more functionality and improves compatibility with our translation plugin suite, WPML: https://wpml.org. Note that you cannot use Toolset's Post Relationships features or WPML's related posts translation features if you decide to continue using the custom field approach to link two posts using a related parent post ID.

If you want to switch to Toolset's Post Relationships feature, you must create a relationship between the two post types in Toolset > Relationships and establish your Post Relationships in the post editor screen, or export your child posts with custom field values into a CSV file using WordPress's built-in export tool. Format the CSV appropriately and re-import the child posts following the procedure outlined here: https://toolset.com/course-lesson/importing-content-from-csv-with-post-relationships/
Then the Toolset import / export tool can convert these imported relationships into the proper Toolset Post Relationships structures.

Once those Toolset Post Relationships are configured, you can easily set up a View that displays related posts by following these instructions:
https://toolset.com/course-lesson/displaying-related-posts/

Instead, if you want to continue using the custom field approach with a stored post ID instead of Toolset's Post Relationships features, you can set up a View of the paidview post type with a Query Filter based on the custom field value, supplied by a shortcode attribute. See query-filter.png for an example of such a Query Filter setup. My custom field in this example is book-single-line-1, but yours will be different.

To access Query Filters in the Block Editor: https://toolset.com/course-lesson/creating-a-view/#filter-the-list-of-posts
In the legacy Views editor, you can expose the Query Filter panel in Screen Options at the top of the editor page, if the Query Filter panel is not already visible in the editor.

After configuring the Query Filter you must insert the View in your Seller post or Seller post template design using a wpv-view shortcode, and pass in the Seller post ID using a shortcode attribute:

[wpv-view name="your-view-slug" parentid="[wpv-post-id]"]

Note that you cannot use shortcode attributes with the Views block in the Block Editor. This is a limitation of the current Toolset Blocks implementation. You must insert the View using a shortcode as described above. If you are using Toolset Blocks, you can access the View slug by enabling both the legacy editor and the blocks editor in Toolset > Settings > Front-end Content: Editing experience. Then a Views menu item will appear in the Toolset menu. Edit the View to find the View slug.

Let me know if you have questions about either approach, and I can offer more direct guidance.

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