Home » Topics » Pods 1.x » Trying to retrieve multiple pods via pick field, no matching image?
Trying to retrieve multiple pods via pick field, no matching image?
This topic contains 2 replies, has 2 voices, and was last updated by redconservatory 2 years, 9 months ago.
-
AuthorPosts
-
August 12, 2010 at 12:30 am #163906
I am trying to retrieve information from a pods called "related_artists" using:
123// artist info, returns an array$episode_artist = $episode->get_field('related_artists');$episode_artist_imageID = $episode->get_field('related_artists.artist_image.ID');So far, so good. I am getting 3 items per array ($episode_artist, $episode_artist_imageID). But when I write:
12345$episode_artist_3_firstname = $episode_artist[2]['name'];$episode_artist_3_lastname = $episode_artist[2]['last_name'];$episode_artist_3_permalink = $episode_artist[2]['slug'];$episode_portrait_3_array = wp_get_attachment_image_src($episode_artist_imageID[2],'thumbnail');$episode_artist_3_artist_thumb_src = $episode_portrait_3_array[0];The first name, last name, and permalink all correspond to the same artist (good!) but the image is a photo of a totally different artist.
After looking at the database…it seems like "name" "last name" and "permalink" are all in the same table ("episode") but it looks like pods stores the images elsewhere. Maybe this explains why pulling artist_thumb[0] won’t match firstname[0]?
Is there any way to make sure that images that are part of a "pod" relate to the corresponding name?
August 13, 2010 at 4:51 am #163907I’d suggest making a different approach, the current way you are doing it assumes a few things that could change, and the order of the field data returned isn’t always perfect unless you apply a second variable to the get_field(‘field_name’,'id’) to order by id, or you can use ‘name’ too.
I suggest looping through the related_artists and setting up a new pod like $episode_artist = new Pod(‘artist’,$artist_id); and then utilizing that variable for your artist-related data. Don’t be afraid about performance on a big page, Pods caches these queries so pulling the same artist multiple times won’t bleed you dry.
August 16, 2010 at 3:53 pm #163908With Scott’s help, got it working…here’s a bit of the code in case anyone has something similar.
123456789101112131415161718192021222324252627282930313233343536373839404142<?php/* Template Name: your-template-goes-here */get_header(); ?><?php$found_episode = false;global $pods;$episode_slug = pods_url_variable('last');$episode = new Pod('episode', $episode_slug);if( !empty( $episode->data ) ){$found_episode = true;// set our variables$episode_id = $episode->get_field('id');$episode_name = $episode->get_field('name');// get the id for our "related_artist" pod (returns an array)$artist_id = $episode->get_field('related_artists.id');for ($counter = 0; $counter < 3; $counter += 1) {$episode_artist = new Pod('artist',$artist_id[$counter]);// set our variables${"episode_artist_".$counter."_firstname"} = $episode_artist->get_field('name');${"episode_artist_".$counter."_lastname"}= $episode_artist->get_field('last_name');${"episode_artist_".$counter."_permalink"} = $episode_artist->get_field('slug');$artist_image_id[$counter] = $episode_artist->get_field('artist_image.ID');// get our thumbnail using wp_get_attachment_image_src$episode_artist_arr = wp_get_attachment_image_src($artist_image_id[$counter],'thumbnail');${"episode_artist_".$counter."_thumb_src"} = $episode_artist_arr[0];}}?>This loop creates variables named:
123456episode_artist_0_thumb_src,episode_artist_1_thumb_src,episode_artist_2_thumb_src,episode_artist_1_firstname,episode_artist_2_firstname,etc...etc
-
AuthorPosts
You must be logged in to reply to this topic.