Returning array values in a PICK column

0

I have 2 pods, projects and types. I have a PICK column that is types and multiple types can be assigned to a project. I am sure this is simple, but I cannot figure out how to return all of the types chosen. I can successfully return the first value, projecttype.name, but that is it. Any with multiple selections return arrays. I have tried looping through the array, but can't get it to work. Is that the way I need to go?

Thanks for any suggestions.

Shawn

asked Dec 2 '11 at 9:00

senojeel

3

add comment
enter at least 15 characters

8 Answers

0

Hey Shawn, You need to use a display helper to enumerate the elements of the array. Check this link

http://podscms.org/codex/display_helpers/

on how to use display helpers. There's a few examples there that might be of help too. But here's a display helper that will list out your array elements as a comma separated list.

Try this:

<?php
if(is_array($value) && !empty($value)) {
    $v = $value;
    $comma_separated = implode('<br/>', $v);
    // display the list
    echo $comma_separated;

} else {
    $v = $this->get_field($name);
    // display the single group
    echo $v;
}
?>

answered Dec 4 '11 at 5:25

magi182

110

edited Dec 4 '11 at 5:27

add comment
enter at least 15 characters
0

Thanks. I get that, but 2 things.

  1. When I am editing my pod column, here is no Display Helper dopdown.

  2. If I try to use it in my template, I put the code in and assign it a variable, then echo the variable. That doesn't seem to work.

    `$project_projecttype = $pods->pod_helper('pick_array', $pods->get_field('projecttype'));

    echo $project_projecttype; `

pick_array is what I named the Display Helper.

I am I even close?

answered Dec 6 '11 at 7:27

senojeel

3

edited Dec 6 '11 at 7:27

add comment
enter at least 15 characters
0

If you're using this in a Pods Template, your code should look like this:

{@projecttype, pick_array}

If you're using this in a Pods Page or a WP Template, I wouldn't create a helper, I'd just write the PHP code:

$pt = $pods->get_field('projecttype');
if(is_array($pt) && !empty($pt)) { 
    echo implode(', ', $pt);
}

If that still isn't working, you might need to inspect what that array looks like to make sure it doesn't have multiple indexes (e.g. implode(', ', $pt[0]) ):

$pt = $pods->get_field('projecttype');
echo "<pre>\n"; print_r($pt); echo "</pre>\n";

answered Dec 6 '11 at 8:19

chris.pilko

889

add comment
enter at least 15 characters
0

I am using a WP template.

This is what happened before when I was tying other things...Wherever I place the code, the page stops executing and is just blank after that. It is like it breaks the loop.

Here is the page without the code from above. http://test.cmfi.org.php5-10.websitetestlink.com/partner

answered Dec 6 '11 at 8:47

senojeel

3

add comment
enter at least 15 characters
0

It sounds like you've got a syntax error in your PHP code somewhere. If you can, run a syntax check on your dev machine "php -l myfile.php" or run it through an online tool.

answered Dec 6 '11 at 10:45

chris.pilko

889

add comment
enter at least 15 characters
0

That is a great online tool. I am getting this error:

array($pt) && !empty($pt)) { echo implode(', ',$pt);

answered Dec 6 '11 at 11:13

senojeel

3

add comment
enter at least 15 characters
0

Not sure how this reports the error, but looking at the string you've got, you've either missed the underscore in is_array() (array() is a declaration) or you're missing the closing } in your if statement.

answered Dec 7 '11 at 3:06

chris.pilko

889

add comment
enter at least 15 characters
0

I really appreciate your help with this Chris.

I have it working now. Not exactly sure what was wrong, but went in and retyped everything and it worked after that. May have had some gremlins in there.

answered Dec 7 '11 at 4:07

senojeel

3

add comment
enter at least 15 characters