Support » Plugin: Pods - Custom Content Types and Fields » Fail to pass @ID to function in pods template

  • Resolved max1024

    (@max1024)


    tried to follow
    https://docs.pods.io/code-snippets/return-calculated-value-pods-template/#masthead

    <div class=”row”>
    <div class=”col-6″>Total hrs:</div>
    <div class=”col-6″> {@ID,calculateHours}</div>
    </div>

    but function receive empty $id
    function calculateHours($id) {
    $course = pods(‘course’, $id);

    if ($course->exists()) {
    return $course->filed(‘hours’)+$course->filed(‘conshours’)+$course->filed(‘examhours’)+$course->filed(‘projecthours’);
    } else return $id;
    }

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

    (@keraweb)

    Hello @max1024

    Where are you using the template code?
    This is intended for a Pods Template. The function itself should be added in your theme.

    Cheers, Jory

    Hi
    sure, im using it with pods plugin
    function is in functions.php
    So function is called ok, but ID comes empty

    Plugin Author Jory Hogeveen

    (@keraweb)

    How are you fetching the Pods Template?
    A shortcode? Auto-templates? Something else?

    Cheers, Jory

    shortcode

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @max1024

    I’d need a bit more than just “shortcode”..

    – Please share your shortcode (just copy it)
    – Also let me know where this shortcode is used in your site

    You’ll need to share all related info about this issue otherwise it’s impossible for me to properly help you.

    Cheers, Jory

    On page:
    [pods name=”course” id=1 template=”ListCourseDetails”]

    template:

    <div class=”row”>
    <div class=”col-6″>Total hrs:</div>
    <div class=”col-6″> {@ID,calculateHours}</div>
    </div>

    Function:

    function calculateHours($id) {
    $course = pods(‘course’, $id);
    if ($course->exists()) {
    return $course->filed(‘hours’)+$course->filed(‘conshours’)+$course->filed(‘examhours’)+$course->filed(‘projecthours’);
    } else return $id;
    }

    • This reply was modified 1 month, 3 weeks ago by max1024.
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @max1024

    And you say that the $id parameter is empty in your function? Did you check with a var_dump or something similar?
    If so, I cannot reproduce your issue locally so there must be something else wrong. Maybe a plugin conflict? https://docs.pods.io/faqs/plugin-theme-conflicts/

    I also noticed you are calling a method I do not recognize named filed. This isn’t a method from the Pods object.
    Shouldn’t this be field?

    Cheers, Jory

    Plugin Author Jory Hogeveen

    (@keraweb)

    Closing topic due to no reply.
    Feel free to re-open if you still need help!

    Cheers, Jory

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.