Hi there!
You can update the views count via AJAX as well. Here’s an example:
jQuery.post(
'<?php echo admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'); ?>',
{
action: 'update_views_ajax',
token: '<?php echo wp_create_nonce('wpp-token') ?>',
wpp_id: POST_ID_HERE
},
function(response){
}
);
This code should be executed after your AJAX call has been executed.
i have another question please in the code you mentioned above , should i leave the part of “admin-ajax.php” as you mentioned it ? i did another thing , in the ajax call after retrieving the info i already added an query to increment the views , so it’s already incremented in the database but in the side bar still the same number of views the page should be refreshed in order to update the number of views ,, if i used your code here would it be updated in the bar automatically without refreshing the page ?
i have another question please in the code you mentioned above , should i leave the part of “admin-ajax.php” as you mentioned it ?
Keep in mind that that code is just an example. Leaving that part as is won’t hurt, though.
in the ajax call after retrieving the info i already added an query to increment the views , so it’s already incremented in the database but in the side bar still the same number of views the page should be refreshed in order to update the number of views ,, if i used your code here would it be updated in the bar automatically without refreshing the page ?
Nope. The code I posted above simply updates the views count. The widget in the sidebar would still need to be reloaded in order to show the updated info.