• Resolved msowah

    (@msowah)


    I recently saw a pod update that had this new addition:
    2.8.15 – April 16th, 2022
    Added: New pods_callback support in Pods::find() so that you can pass a callback function to use for pods() usage with relationships using the output as “pods”. This allows for using shared instances across large data sets to reduce time. (@sc0ttkclark)

    Can you help with a code example because I can’t find any sample anywhere? thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    It’s used by a project of mine which holds a shared Pods object. Passing a callback function to the parameter let’s you use anything that ultimately returns a Pods object itself. The default is still to use the normal pods() function.

    When using a relationship field that’s related to another Pod, the output parameter allows you to return it as a “pod” (pod passes an array of Pods objects) or “find” (find uses a Pods object but fills it with records that can be run through using a fetch() while loop).

    I don’t have an example of the callback right now but I hope to have something that can be tapped into in the near future. I’m using a form of it with the Pods Templating in the Templates component but it’s not abstracted for general use in the way I have it for my custom project.

    Thread Starter msowah

    (@msowah)

    Thanks for the swift response,e all am trying to find out is after using the normal pods() where or how do I pass the pods_callback in other to get all the fields of the relationship field…I really appreciate a sample…is it passed like the ‘where’ or am I missing something here.

    How do I add the pods_callback in the sample below:

    // Here's how to use find()
    $params = array(
        'limit' => 3, 
        'page' => 2, 
        // Be sure to sanitize ANY strings going here
        'where'=>"category.name = 'My Category'"
    );
    // Run the find
    $mypod = pods( 'mypod', $params );
    // Loop through the records returned
    while ( $mypod->fetch() ) {
        echo $mypod->display( 'name' ) . "\n";
    }
    • This reply was modified 2 years, 7 months ago by msowah.
    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    Sorry, there was a typo in that changelog that I’ll fix in the next release. The support for pods_callback was added to Pods::field() and not Pods::find().

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘pods_callback’ is closed to new replies.