Trying to use the "Custom Function" feature to display terms in a Date Descending Format

I created function called “cs_looper_custom_latest_series.” I’m able to call it in Cornerstone using the custom call for looper providers. As you can see below:

Screenshot 2023-05-16 092331

This does work but the output is just a list of links right next to each other without any formatting. I’m trying to use my function to style the output in the cornerstone builder rather than having to do custom HTML and CSS to get it to look right. I’m sure I’m just missing a step, but help would be appreciated. Thanks!

Here’s the code I have for my loop.

function cs_looper_custom_latest_series() {
$terms = get_terms(array(
    'taxonomy'   => 'sermon-series',
    'hide_empty' => true,
    'orderby'    => 'date',
    'order'      => 'DESC',
));

if (!empty($terms)) {
    $current_term = get_queried_object(); // Assuming you are on a single sermon page
    $current_term_id = $current_term->term_id;

    foreach ($terms as $term) {
        if ($term->term_id === $current_term_id) {
            echo '<span class="current-term">' . $term->name . '</span>';
        } else {
            echo '<a href="' . get_term_link($term) . '">' . $term->name . '</a>';
        }
    }
}
}
add_filter('cs_looper_custom_latest_series', 'cs_looper_custom_latest_series');

I can’t seem to figure out how to see the output of the loop in cornerstone even though the loop is working on the frontend.

Hello Tyler,

Thanks for writing in!

Your code outputs HTML which is unusable in Cornerstone. Please be advised that a Looper should return an object or an array to be usable by the Looper Provider. You need to revise your code. Please check out this documentation first:

Best Regards

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.