• Resolved robbiejackson

    (@robbiejackson)


    Hi,
    I’ve got a Walks pod which is Pod Custom Post Type.
    It’s got a field walk_place which is a Relationship field to a Pod Custom Taxonomy called Place.
    The Place custom taxonomy has a number field called latitude.

    Inside a pods template for a single Walk I can do:
    Latitude: {@walk_place.latitude}
    and this outputs the latitude field correctly.

    However, the walk_place field is optional, so I want to do:

    [if walk_place]
    Latitude: {@walk_place.latitude} 
    [/if]

    However, this just outputs the string “Latitude:” but not the value.

    What should I be doing? (I’ve also tried just {@latitude} but it doesn’t work either).

    Thanks for your help,
    Robbie

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    You can’t ‘traverse’ relationship fields in an [if][/if] statement, so you can’t do something like:

    [if walk_place.latitude]

    This is a limitation of the template tags and we know it needs to be addressed.

    What I would do is pass your field to an external function, like {@walk_place.latitude,show_my_latitude_field} and your show_my_latitude_field would handle checking the value of the field and adding the Latitude: label.

    Or you could alternately use PHP in a WordPress Theme Template.

    Thread Starter robbiejackson

    (@robbiejackson)

    Thanks for the clarification Jim. In the end I went down the route of using php.

    I was a bit unsure about how to go about the php route though – is there any Pods documentation which describes what to do? I know there’s descriptions of Pods templates and of Pods pages, but the latter seem to be just for advanced content types.

    I didn’t want to modify my theme’s files, so what I did was:

    • Create a child theme
    • Copy the main theme’s single.php file into a new file single-walk.php in my child theme
    • Edited this single-walk.php file to get what I wanted using code below to get the Pod record
     $walk = pods( 'walk', get_the_id() );
     if ( $walk->exists() ) {
          $myfieldvalue = $walk->field('myfieldname');   
          ...

    This worked fine, but is it anything like a recommended approach?

    Thanks,

    Robbie

    • This reply was modified 7 years, 6 months ago by robbiejackson.
    Plugin Contributor Jim True

    (@jimtrue)

    That’s the approved method. Create a child theme, create a singular post PHP theme file and handle it within. Documentation-wise, you’re looking at the PodsCast’s on Displaying Pods Data in your Theme:

    http://pods.io/2015/04/03/podscast-003-displaying-data-in-pods-pt-1/
    http://pods.io/2015/04/16/podscast-004-displaying-data-pt2/

    Thread Starter robbiejackson

    (@robbiejackson)

    Thanks Jim, I went through the videos and was reassured that I was doing it correctly.

    I’d happily write up a little tutorial on this topic and send it to you if you feel you’d like to have some written documentation as well on your site. I don’t do blogs, so I wouldn’t have anywhere I could host it myself.

    If you’re interested, let me know where I could email it, plus in what format it would be best to write it (eg .doc file, html etc).

    Cheers
    Robbie

    Plugin Contributor Jim True

    (@jimtrue)

    Howdy Robbie,

    You can drop onto our Slack Chat at http://pods.io/chat/ in the #support channel or you can send me an email with your tutorial and I’ll get it added.

    Thanks!
    Jim

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pods template – custom taxonomy magic tags in [if] statements’ is closed to new replies.