How to use display helper on page template?

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  maor 3 years, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #161916

    maor
    Member

    Well, I found some help on the codex, and tried this:

    <pre>
    $meeting_city = $Record->pod_helper(‘filter_helper’, $Record->get_field(‘city’));
    </pre>

    But when I echo the the variable, nothing gets as an output. But with the same helper, when the code was first on the POD template (e.g. {@city, filter_helper} ) , it did work.

    This is my filter_helper:

    <pre>
    <?php
    $pick_array = $this->get_field($name);
    $tmp = explode(‘?’, $_SERVER['REQUEST_URI']);
    $link = $tmp[0];
    parse_str($_SERVER['QUERY_STRING'], $tmp_query);

    if (is_array($pick_array) && 0 < count($pick_array)) {
    $output = "";
    $sep = "";
    foreach ($pick_array as $val) {
    $output .= $sep;
    $tmp_query[$name] = $val['id'];
    $output .= "<a href=’" .$link ."?" . http_build_query($tmp_query) . "’>";
    $output .= $val['name'] . "</a>";
    $sep = ", ";
    }
    echo $output . "";
    }
    ?>
    </pre>
    Should I change something in the helper as well?

    #161917

    logikal16
    Member

    @maor – I know it’s poorly documented, but pod_helper() accepts 3 parameters:

    1st: Helper Name
    2nd: Value to pass into helper
    3rd: Column name

    Notice how in your helper, you’re trying to use get_field($name). Since the name parameter isn’t getting passed in, nothing is getting found from get_field().

    Try this instead:

    <pre>$meeting_city = $Record->pod_helper(‘filter_helper’, $Record->get_field(‘city’), ‘city’);</pre>

    #161915

    maor
    Member

    Hi,

    I had a POD template that showed the columns using a display helper, something like this:

    <pre>
    {@city, filter_helper}
    </pre>

    This helper is used to show the column’s value (since it’s a PICK array) and have it clickable to be filtered.

    Now, I want to move the POD template, to be directly inside my WordPress page template. I use the code, something like:

    <pre>
    while ($Record->fetchRecord()) {
    $meeting_city = $Record->get_field(‘city’, filter_helper);
    echo ‘<div class="cell alignright">’ . $meeting_city . ‘</div>’;
    some more fields here…etc…
    } // end while
    </pre>

    That brings me an error, and doesn’t recognize the helper as an helper, but as an orderby field.
    More than that, if I put just –
    <pre>
    $meeting_city = $Record->get_field(‘city’);
    </pre>
    It echoes an "Array" as a result.

    So, how do I use my display helper when my code is directly on the WP page template, and not on a POD template?

    Thanks

    #161918

    maor
    Member

    @logikal16 – Many thanks, it works great now!

    Just for curiosity, if I understood the logics here, the value is passed from the column name that is already mentioned in the get_field(), so why does the pod_helper() must get both the value and the column name, rather than have the value pass its column name to the helper as well?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Wordpress Cloud Hosting