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