Last active
November 10, 2017 08:45
-
-
Save lasida/fdce84cae22f0032a07bcb0007668da7 to your computer and use it in GitHub Desktop.
Ajax View Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(window).load(function() { | |
$.ajax({ | |
url : kontakin.ajax_url, | |
type : 'post', | |
data : { | |
action : 'add_kontakin_view', | |
post_id : postID | |
}, | |
success : function( response ) { | |
window.location.replace(linkdirection); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_kontakin_view() { | |
$view = get_post_meta( $_POST['post_id'], 'kontakin_view', true ); | |
$view++; | |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | |
update_post_meta( $_POST['post_id'], 'kontakin_view', $view ); | |
echo $view; | |
} | |
die(); | |
} | |
add_action( 'wp_ajax_nopriv_add_kontakin_view', 'add_kontakin_view' ); | |
add_action( 'wp_ajax_add_kontakin_view', 'add_kontakin_view' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wp_enqueue_script( 'kontakin-functions', get_template_directory_uri() .'/js/functions.js', array('jquery'), null, true ); | |
wp_localize_script( 'kontakin-functions', 'kontakin', array( | |
'ajax_url' => admin_url( 'admin-ajax.php' ), | |
'pixel' => get_field('kontakin_facebook_pixel_id','option') | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment