Is it possible to populate a repeating image field within a CPT with images from linked posts via a relationship?
For example;
Imagine I have a relationship connecting CPTs Authors to Books. I then have a repeatable CF of Image within the Author CPT. Could I populate this Image field with the Featured Images from all of the connected 'Books"?
I hope this makes sense, please let me know if you need me to clarify anything.
Hello,
I don't think it makes sense, since you have already setup the post type relationship between post type "Author" and "Books", so I don't think the "repeating image field" is required, since you get those related "Books" information with a post view, see our document:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
Displaying many related items
And there isn't such kind of feature within Views plugin:
populate a repeating image field within a CPT with images from linked posts via a relationship
Thank you for the reply Luo Yang!
I am aware that I can display the related images through a post relationship query in Views, but I am in need of having these images to be populated on a repeating custom field on the parent post.
I take it that this is impossible to do however?
No, there isn't such a built-in feature within Types plugin, you might consider custom codes, for example, when user create/edit a "Author" post, you can use WordPress action hook "save_post" to trigger a PHP function
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
in this function do these:
1) Get the related "Books"
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
2) get the featured images of each "Books" post:
https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/
3) And save them into your custom repeating image field:
https://developer.wordpress.org/reference/functions/update_post_meta/
For your reference.
Thank you kindly for the response Luo Yang.
Is there any way somebody could break this down for me a bit more or walk me through some of the steps I'd need to take?
As you can see, within Toolset, you can display the same result without "populated on a repeating custom field on the parent post":
https://toolset.com/forums/topic/populate-repeating-image-field-with-images-from-linked-posts-via-relationship/#post-1201538
If you insist on custom codes to "populated on a repeating custom field on the parent post", according to our support policy, we don't provide custom codes support
https://toolset.com/toolset-support-policy/
You can also check it with our Toolset contractors:
https://toolset.com/contractors/
As per my reply #1202560, I am aware that I can display the related images through a post relationship query in Views, but I was in need of having these images to be populated on a repeating custom field on the parent post for a different reason.
Thank you for your help with this Luo Yang.