Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEric Mayfield
3,312 PointsHow-to link relationship based custom post types / advanced custom fields?
Would be super grateful if anyone could throw me some suggestions on how to link custom post types / custom fields using the plugins from Zac's awesome videos.
Essentially what I'm trying to achieve is to have two custom post types:
- Artists
- Artwork
Artists will be comprised of various fields as Name, Description, Photo
Artwork will be comprised of Name, Description, Image, and relationship tying it to an Artist.
What I'm trying to achieve is to show any artwork related to Artists on their Artist page dynamically. So if new art is added it would auto show up on whichever Artist page the Art was related to.
Again I appreciate any help anyone could give me. :)
3 Answers
Anthony Moore
2,282 PointsIt looks like you would want to run a meta query.
http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
Or, if you are using the "Relationship" field from ACF you check out the code examples here:
http://www.advancedcustomfields.com/resources/field-types/relationship/
Eric Mayfield
3,312 PointsAnthony thanks for the reply, I had actually already tried following along with that code example from ACF but ran into issues with the meta-query in regards to getting it to produce the correct URL for my <img src code, if memory servers you set a variable such as $photo to the getField( 'image' ) tag, then you attempt to pull out the url index by $photo[ 'url' ], I do remember that it kept giving me "h" as the url but would never return the correct url for the image.
What I'll do in the meantime is to review this information from ACF again and take a look at the WP codex for field parameters and try again, if successful this go round awesome, I'll report a thumbs up. If I run into problems again I'll return here prepared with code examples which may help aid in some of you guys helping me pinpoint my issue.
Thanks!
Anthony Moore
2,282 PointsYou will want to make sure that in your custom field setting for the image field, that you select "Image URL" for the return value.
Eric Mayfield
3,312 PointsActually this wasn't the issue, in fact the opposite, the problem was I did have it set to Image URL when it should have been set to object. As an object it allows the image to have meta fields that you can access such as url, name, alt, description, caption, etc. basically the stuff that you associate with an image when you upload it via the media uploader.
Eric Mayfield
3,312 PointsSo I have everything on that end worked out, but my major problem now is that it is only outputting 5 images associated with an artist even if I have more. I can tell it isn't an html/css issue, as in css hiding code, or images dropping off the page, definitely in the loop, as I setup a counter and the loop only goes through 5 times, I don't have anything setup to limit it to only get 5 posts, so I'm fairly confused. I'm going to close this out and open a new post for my new issue.