• Resolved harryfear

    (@harryfear)


    Does pods not provide a function like get_the_field or the_field to return field values like ACF?

    In our desired use case, we want to return a value of a field from a Pods settings page.

    For now, we have polyfilled with a custom snippet function that executes the do_shortcode for “[pods ……]” but this is not very clean.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    For settings pages, you can use get_option() https://developer.wordpress.org/reference/functions/get_option/

    But Pods does actually include ACF compatibility so you could technically use the same functions you used in ACF for that part 🙂

    Pods has it’s own functions for this though, so if you want to do it the normal Pods way then you can follow the docs here:

    • Optimized for multiple field lookups, use our Pods object and the field() or display() method depending on use-case
    • Global functions that map to our Pods object but could increase memory usage at scale because they need to do additional set up for each call, use pods_field() or pods_field_display()

    Hope this helps clear things up for you, happy Pods-ing!

    Thread Starter harryfear

    (@harryfear)

    Thanks so much!

    For posterity, we ended up with this:

    
    echo pods_field('site_settings',null,'banner_text')
    
    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Any time you echo, you should use pods_field_display in that context. Always use the display() variation because it handles output escaping for you. Otherwise, be sure to update your code to something like this to escape it on your side:

    echo esc_html( pods_field( 'site_settings', null, 'banner_text' ) );

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    If your Pods field allows for HTML, then display() will handle all of the logic needed to ensure only the HTML tags you allowed will be output. This is generally necessary for security when you offer fields like these because someone could gain access to your DB and be able to hijack your output without you ever knowing.

    Thread Starter harryfear

    (@harryfear)

    Thank you! That’s perfect!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Field Return Function’ is closed to new replies.