Skip Navigation

[Resolved] Types Beta 2.3 – new relationships moved out of post meta

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

This topic contains 8 replies, has 2 voices.

Last updated by Geoffrey Cleverley 6 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#601753

Hey there Guys,

Been a while.

I am building out a site, and trying out the new Types beta for its many to many relationships etc, but I'm not using views and wanting to build up my own templates, using either standard WP functions or the Toolset API, whichever is most appropriate.

I am aware that you have moved the parent/child relationships out of the wp_postmeta into their own table, but I can't find any links or forum posts or information about how to access them with the new API.

So, could you help me?

Examples of what I need:

1. One to Many relationships - getting data from parent.

CPT A - slug = 'record-label'
CPT B - slug = 'music-release'

One CPT A to Many CPT B

To get the data from the record label while in a music-release template, In the past I would have just done something like:

e.g get the record label name to display on the music release

$record_label_id = wpcf_pr_post_get_belongs( get_the_ID(), 'record-label' );
$record_label = get_post( $record_label_id);
$record_label_name = $record_label->post-title;

echo $record_label_name;

or more probably (cutting out the API saves a few cycles)

$record_label_id = get_post_meta( get_the_ID(), '_wpcf_belongs_record-label_id', true );
$record_label = get_post( $record_label_id);
$record_label_name = $record_label->post-title;

echo $record_label_name;

or something similar, depending on what data I wanted to display.

But this isn't working anymore, due to the Types API function wpcf_pr_post_get_belongs() just constructing a similar call to get_post_meta as above in the second example.

Since the information about parent and children isn't stored in the postmeta table anymore, none of these work.

2. Many to Many - getting data from child, and child's other parent.

CPT B - slug = 'music-release'
CPT D - slug = 'music-store'
CPT E - slug = 'music-purchase-channel' (Intermediate Post Type) - has custom field 'wpcf-purchase-link' (url)

I might have used

$purchase_channels = types_child_posts( 'music-purchase-channel ');

foreach ($purchase_channels as $purchase_channel) {
    $music_store_id = wpcf_pr_post_get_belongs( $purchase_channel->ID, 'music-store');
    $music_store = get_post( $music_store_id);
    $music_store_name = $music_store->post-title;
    $purchase_link = get_post_meta( $purchase_channel->ID, 'wpcf-purchase-link', true);

    echo '<a href="' . $purchase_link . '">' . $music_store_name . '</a>';
}

or constructed a query using an $args array, and get_post( $args), you get the gist anyway.

However, again these won't work.

I am not using views, but since views beta is working with the types beta, I figure you have the API working, and would be really really keen on finding out how to do this...

Even if it's just a case of pointing me into the codebase to have a look.

Thanks again Guys.

Jeff

#601793

Nigel
Supporter

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

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

Hi Jeff

The Types beta is intended solely for use with the Views beta.

At the moment there is no API, it is very much as work-in-progress.

Inasmuch as there is any existing code used by the Views beta it isn't documented (it is almost certainly not finalised) and we have been explicitly told not to share any further details, hence I haven't dug any deeper into the code itself.

I think we are still on target to have a final version "from" the end of January, at which point it should be possible to give details of the API, too, but in the meantime I have nothing to share I'm afraid.

#601803

Hey Nigel, Merry Christmas mate,

Haha that's a real shame, I hope "end of January" becomes reality, this has been a loooooooooong time coming and I'm itching...

Say I want to proceed... I suppose I can use the views beta, and then render out the views in my theme templates via api still though, right?
https://toolset.com/documentation/programmer-reference/views-api/

Jeff

#601808

Nigel
Supporter

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

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

Sure, yes, it is specifically the parts of the APIs that involve post relationships that are affected, the rest should work as before.

You would be able to create Views that use post relationships and render them in your PHP templates using do_shortcode.

#602150

Hey Nigel,

Since I am using views, I am using the render_view() function from the API.

However I am still having a little trouble.

In the new many to many relationships I have

Music Release CPT - 'music-release'
Music Store CPT - 'music-store'

Then as an intermediary I have
Purchase Channel CPT - 'purchase-channel'
Custom Fields - 'purchase-link' & 'price'

So when I am querying the for the music stores and download links I want to do something like this:

<a href="$purchase-link">$music-store - $price </a>

In the pre beta I would create a view that queried the intermediate 'purchase-channel' post type with a template like the following:

<a href="[types field="digital-purchase-link" output="raw"][/types]" target="_blank">[wpv-post-title id="$music-store"]- [types field="digital-release-price"][/types]</a>

But with the new relationships, I can't query the intermediary post. I can easily query the other post connected through the relationship though.

How do I access these 'custom fields' that I set up when I created the relationship?

Is this what is meant by:

Missing - Proper GUI for setting up the display for Post Reference custom fields

That was mentioned in the beta release blog post?

Thanks

Jeff

#602548

Nigel
Supporter

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

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

Hi Jeff

Sorry for the delay getting back to you over the holidays.

If you create a relationship and the relationship itself can have custom fields, then an intermediate post type will be created and used to store the custom fields against.

So if you create a M2M relationship between "music-release" and "music-store" then that would create an intermediate post type of "music-release-music-store", stored in wp_posts, with the custom fields stored in wp_postmeta.

The problem is that the API does not currently provide any way of getting the id of the intermediate post to retrieve the required custom fields.

That is missing from the beta, but should become available with the stable versions.

#602550

Hey Nigel,

No worries, hope you had a great holiday!

Yeah, in the blog post it says:

"This release of Views includes a lot of the planned support for post relationship, but not all. Among the missing feature (in this beta) are:

  • Support for many-to-many filters in custom searches
  • Proper GUI for setting up the display for Post Reference custom fields
  • Convenient display for repeating field groups
    All this will come in the next Views beta, right after the holidays."

    So I have my fingers crossed that another beta is still scheduled for arrival soon, any chance of that before stable?

    Jeff

#602611

Nigel
Supporter

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

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

Hi Jeff

I checked with the developers and there will be at least one more beta release of Types and of Views, plus a beta of CRED, before the stable releases are published, but there is no timeline for when they will be available.

Sorry, but they don't want to make any promises that they might be unable to keep.

#602612

No worries Nigel, cheers for enquiring.

I have plenty to be getting on with in the meantime.