1

I'm having problems when trying to access data that I've queued using the Heartbeat API.

I'm queuing data using wp.heartbeat.enqueue(). For example:

var data = { 
    my_key: 'value'
};
wp.heartbeat.enqueue( 'my_handle', data, false );

Then later on in my script, I'd like to access the data I've queued. For example:

$( document ).on( 'click', '#button', function() {
    // Here, I want to access the data I've enqueued.
});

I've tried doing the following but that doesn't work:

$( document ).on( 'click', '#button', function() {
    var my_data = wp.heartbeat.getQueuedItem( 'my_handle' );
    alert( my_data.data.my_key );
});

Hoping someone can suggest where I'm going wrong?

2

I found the solution to my problem was to change my_data.data.my_key to my_data.my_key. For example:

$( document ).on( 'click', '#button', function() {
    var my_data = wp.heartbeat.getQueuedItem( 'my_handle' );
    alert( my_data.my_key );
});

The queued data can be easily accessed now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.