Stack with trying to retrive corresponding Pods info via PICK column
Hello everyone,
I'm stack with retrieving a corresponding info for a Pod that specified via PICK column. I would really appreciate any help.
I've got 3 Pods: Productions, Reviews and Photos. Reviews and Photos belong to a specific Production and set up via PICK column, i.e. both Reviews and Photos have a PICK column for a Production. I'm trying to display a Production with all corresponding info (general, all Reviews and Photos).
First, I create a Productions Pod by specifying it's slug. I then retrieve Productions id and general info (title, description, start and end dates, ...), which is correct. However, then I'm stack and don't know how to select corresponding Reviews and Photos for a specific Production.
Here is the full code:
<?php
$found_production = false;
global $pods;
$production_slug = pods_url_variable(-1);
$production = new Pod('productions', $production_slug);
if( !empty($production->data) ) {
$found_production = true;
// set production variables
$production_id = $production->get_field('id');
$production_title = $production->get_field('name');
$production_desc = $production->get_field('description_short');
$production_start_date = $production->get_field('start_date');
$production_end_date = $production->get_field('end_date');
$production_theatre = $production->get_field('theatre');
// all reviews for the specified production
$reviews = new Pod('reviews', $production_id); // I don't think this is correct, because $reviews_count ends up being the same for different Productions that some of them don't even have reviews.
$reviews->findRecords('t.id ASC', -1);
$reviews_count = $reviews->getTotalRows();
}
?>
edited Sep 28 '10 at 5:25
3 Answers
I've set up a bi-directional PICK relation:
- in Productions Pod: field "reviews" is a multi-select, bi-directional PICK to the "production_fk" in the Reviews Pod
- in Reviews Pod: field "production_fk" is a bi-directional PICK to the "reviews" in the Productions Pod.
Then, the code to get all the reviews for a production is the following:
// reviews for the specified production
$reviews = $production->get_field('reviews');
$reviews_count = count($reviews);
edited Sep 28 '10 at 5:35
You should use bi-directional pick, it will show all related pods. Another way is to use where clause while requesting photos and reviews, but it is much easier just to drive everything through bi-directional relationship.
@Fike, thanks a lot! Could you explain a bit more about or direct me where I can read up on the bi-directional pick? I would really appreciate it.


