• Resolved jawhalen

    (@jawhalen)


    I used the code you shared in your tutorial:

    $pod = pods( ‘pod_name’, get_the_id() );
    $related = $pod->field( ‘relationship_field’ );

    This page says that returns a multi-dimensional array of all of the items in the related field. That does not appear to be the case. It is an array – but not an array of related items, but rather an array of fields. That being the case, this code does not work if there is only one relative (I have not tested the case where there are more than one relative):

    foreach ( $related as $rel ) {
    $id = $rel[ ‘ID’ ];
    }

    I suspect that this tutorial might need to be clarified to explain that the approach depends on how many relatives there are. Perhaps you can add additional code that checks for that? Also, the opposite scenario is needed – this is “get” code – we also need “set’ code.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hello @jawhalen

    My guess is that you use a single relationship field, not a multiple relationship.
    If you add a second false parameter it should work.
    Otherwise you can remove the foreach loop since it will always return a single result.

    So in short:

    Single relationship: $related = relationship info
    Multiple relationship: $related = array of relationships info

    Cheers, Jory

    Thread Starter jawhalen

    (@jawhalen)

    I was able to find the code I needed. Sugestion: Organize these and show related code links at the bottom of these. For example “set” code should be a related page on the “get” code page. Here is the page (for those looking for the same): https://docs.pods.io/code-snippets/adding-remove-relationship-field-php/

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Tutorial Seems to be Incorrect’ is closed to new replies.