I use WordPress and I want to alert users if new post with post_type = job_post was published. Also I want to show amount of new post.
So I add to function.php
global $new_job_count = 0;
function newJobAdded($ID, $post ) {
$new_job_count = $new_job_count + 1;
}
add_action( 'publish_job_post', 'newJobAdded', 10, 2 );
function mytheme_new_job_count(){
$new_job_count = 0;
}
And I want to show new jobs message to users in main menu
<li class="new_job_count_class"><a href="/newjobs">New jobs count <?php echo $new_job_count ?></a></li>
Also I want to set $new_job_count to 0 if user click on New jobs count message
(function ($) {
$(".new_job_count_class").on("click", function () {
alert('click');
$.ajax({
url: '<?php echo admin_url('admin-ajax.php');?>',
type: 'POST',
data:{
action: 'mytheme_new_job_count'
},
// success: function( data ){
// alert("success");
// location.reload();
// }
});
});
}(jQuery));
Thanks in advance.