Need Code for Nested ACF Relationship Field + PHP Count
- or -
Post a project like this1473
£60(approx. $75)
- Posted:
- Proposals: 2
- Remote
- #2756145
- Awarded
Description
Experience Level: Intermediate
This is a fairly simple project as I only require a short section of PHP code for a Wordpress website using Advanced Custom Fields.
My setup is as follows:
A Custom Post Type called ‘collections’ which has an ACF Relationship field called ‘add_to_collection’, which can be used to add 5 other Custom Post Types (‘fan_art’, ‘cosplay’, ‘fan_fiction’, ‘music’ and ‘video_content’)
Each of those CPT’s has the same Relationship field with the same name ( ‘add_to_collection’ ) and they are-bidirectional using the ACF Extended plugin.
So the idea is for users to be able to create a ‘Collection’ of Fan Art, Cosplay, Fan Fiction, Music and Videos. On each of the content single pages, the item can be added to a Collection individually using a front-end form in a modal. And on each Collection page, multiple content can be added to the Collection. I already have the Collections themselves working, and can already output the posts within the Collection fine and filter them by post type on the front end.
I also have counts implemented, showing how many of each post type is in the Collection.
What I’d like to have on each Collection is some information on the *creators* of each content type. To elaborate, each content type (Fan Art, Cosplay, Fan Fiction, Music and Videos) has another Relationship field to select who *created* the content (not necessarily the author of the post as it’s a fan community that archives fan-created content) – Fan Artist, Cosplayer, Writer, Musician and Video Content Creator, respectively. NOTE: Fan Artists, Cosplayers, Writers, Musicians and Video Content Creators are also Custom Post Types themselves. So when choosing who created the fan content, users are selecting from another Relationship field.
I would like to show for example, a list of Fan Artists, Cosplayers, Writers, Musician or Video Content Creators that are featured in the Collection. To clarify, there is no direct relationship between a creator (e.g. Fan Artist) and a Collection. But it's obviously possible to get fields from the Fan Art that IS directly connected to the Collection.
I've got to a point where I can get a list of the creators FOR EACH item in the Collection, but I only want to show the creators ONCE with a count for how many times they are featured in the Collection.
To keep things simple, I'm okay with getting the code for just one type - for example, Fan Artist, since the code for the other post types would be identical apart from the post type and field names.
To summarise, I want to output the Fan Artists (Relationship/Post Type) connected to the Fan Art (Relationship/Post Type) that is featured in a Collection (Relationship/Post Type). There’s no direct connection of a Fan Artist to a Collection but my understanding is if you get the Fan Art ID, it’s an array that would include the Fan Artist custom field.
And lastly, if possible, I’d want to display the number of a times a Fan Artist is featured in a Collection.
Attached are 2 screens. 1 shows how a Collection single post looks now, with a mockup at the bottom of how I want the 'Fan Artists Featured In This Collection' section to look. The other screen shows what I managed to output myself, but as you can see, it's showing the Fan Artist FOR EACH Fan Art in the Collection, and I only want to show them once.
I can provide more information, including more screenshots to anyone interested. Thank you.
My setup is as follows:
A Custom Post Type called ‘collections’ which has an ACF Relationship field called ‘add_to_collection’, which can be used to add 5 other Custom Post Types (‘fan_art’, ‘cosplay’, ‘fan_fiction’, ‘music’ and ‘video_content’)
Each of those CPT’s has the same Relationship field with the same name ( ‘add_to_collection’ ) and they are-bidirectional using the ACF Extended plugin.
So the idea is for users to be able to create a ‘Collection’ of Fan Art, Cosplay, Fan Fiction, Music and Videos. On each of the content single pages, the item can be added to a Collection individually using a front-end form in a modal. And on each Collection page, multiple content can be added to the Collection. I already have the Collections themselves working, and can already output the posts within the Collection fine and filter them by post type on the front end.
I also have counts implemented, showing how many of each post type is in the Collection.
What I’d like to have on each Collection is some information on the *creators* of each content type. To elaborate, each content type (Fan Art, Cosplay, Fan Fiction, Music and Videos) has another Relationship field to select who *created* the content (not necessarily the author of the post as it’s a fan community that archives fan-created content) – Fan Artist, Cosplayer, Writer, Musician and Video Content Creator, respectively. NOTE: Fan Artists, Cosplayers, Writers, Musicians and Video Content Creators are also Custom Post Types themselves. So when choosing who created the fan content, users are selecting from another Relationship field.
I would like to show for example, a list of Fan Artists, Cosplayers, Writers, Musician or Video Content Creators that are featured in the Collection. To clarify, there is no direct relationship between a creator (e.g. Fan Artist) and a Collection. But it's obviously possible to get fields from the Fan Art that IS directly connected to the Collection.
I've got to a point where I can get a list of the creators FOR EACH item in the Collection, but I only want to show the creators ONCE with a count for how many times they are featured in the Collection.
To keep things simple, I'm okay with getting the code for just one type - for example, Fan Artist, since the code for the other post types would be identical apart from the post type and field names.
To summarise, I want to output the Fan Artists (Relationship/Post Type) connected to the Fan Art (Relationship/Post Type) that is featured in a Collection (Relationship/Post Type). There’s no direct connection of a Fan Artist to a Collection but my understanding is if you get the Fan Art ID, it’s an array that would include the Fan Artist custom field.
And lastly, if possible, I’d want to display the number of a times a Fan Artist is featured in a Collection.
Attached are 2 screens. 1 shows how a Collection single post looks now, with a mockup at the bottom of how I want the 'Fan Artists Featured In This Collection' section to look. The other screen shows what I managed to output myself, but as you can see, it's showing the Fan Artist FOR EACH Fan Art in the Collection, and I only want to show them once.
I can provide more information, including more screenshots to anyone interested. Thank you.
Fireglass Studios
97% (7)Projects Completed
3
Freelancers worked with
3
Projects awarded
75%
Last project
18 Jan 2024
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies