Home › Forums › General Issues › Show online offline status automatically › Reply To: Show online offline status automatically
Hi John,
Please forget everything mentioned above because the circumstances have changed drastically since my last post. So, here comes the new conditions:
A custom post type called “agents” is used to retrieve data from an external api, where all the info about each agent is entered and saved.
I have registered some custom REST fields for all the incoming data (collected by an AJAX call) and then collecting and returning the data for these into any given custom field. This is the code used for that:
// Register custom Rest field
add_action('rest_api_init','itc_custom_rest');
// Collect the data from REST and return the given custom field
function itc_custom_rest() {
register_rest_field('radgivare', 'minutePrice', array(
'get_callback' => function() {
return get_field('price_per_minute');
},
'get_callback' => function() {
return get_field('agent_status_available');
},
'get_callback' => function() {
return get_field('agent_status_inCall');
},
'get_callback' => function() {
return get_field('agent_status_loggedOut');
}
));
}
The new fields show up in REST alright.
My big question now is, can I use the following code in order to echo whatever is retrieved from REST, or do I need to use something else?
// Example used to echo certain colors and texts if the fields (which are type bool) are true
<div class="card__btn-block">
<a href="#" class="btn rounded <?php
if (get_field('agent_status_available')) {
echo $green_status;
}
if (get_field('agent_status_inCall')) {
echo $yellow_border_status;
} else {
echo $red_border_status;
} ?>">
<?php
if (get_field('agent_status_available')) {
echo 'Call Now';
}
if (get_field('agent_status_inCall')) {
echo 'In Call';
} else {
echo 'Offline';
}
?></a>
</div>
Thank you very much for your superior efforts of helping clueless people like myself!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.