How to assign a class on the $value within add_filter

28 Views Asked by At

I have this add_filter code.

add_filter( 'wp_nav_menu_objects', function ($items, $args) {
    $request_item = NULL;
    foreach ($items as $item ) {
        if ('/request/' == $item->url) 
            $request_item = $item;
    }

    if ($request_item) {
        if (ubitto_has_request_answer_permission()) {
            $user_id = get_current_user_id();

            global $wpdb;
            $count = $wpdb->get_var("select count(1) from {$wpdb->prefix}ub_request r inner join {$wpdb->prefix}posts p on r.topic_id = p.ID where r.end_date is null and
                (r.coupon_id is null or exists(select 1 from {$wpdb->prefix}ub_coupon c where c.id = r.coupon_id and c.type = 'request' and c.author_id = {$user_id}))");
            $request_item->title = "Learners' requests - $count";

        } else {
            $request_item->title = "My requests";
        }
    }

    return $items;
}, 10, 2);

I hope to apply a class='count' on the value of $count above...

[enter image description here

Do you have any idea how to achieve this? I have super basic code understanding.

I already have the css ready

Thank you

0

There are 0 best solutions below