Support

Account

Home Forums General Issues update_sub_field on click of ad image

Unread

update_sub_field on click of ad image

  • Hi, I try to update a subfield of repeater for count click on an ad image.

    I’ve tried this solution but don’t work properly. Can you help me?

    HTML
    <a href="https://google.it" class="count" data-post="1" data-row="$i"><img src="/image.jpg"></a>

    JS

    jQuery( ".count" ).click(function($) {
        var post_id = $(this).data('post'); 
        var row     = $(this).data('row'); 
        $.ajax({
         type:"POST",
         url: 'https://site.com/wp-admin/admin-ajax.php',
         data: {
            'action':'update_counter',
            'post_id' : $post_id,
            'row' : $row
         }
         }); 
    });

    PHP (in plugin function.php)

    function update_counter() {
        $post_id = trim($_POST['post_id']);
        $row     = trim($_POST['row']);
        update_sub_field( array('ad', $row, 'click'), 'Test', $post_id);
        exit();
    }
    add_action('wp_ajax_update_counter', 'update_counter');
    add_action('wp_ajax_nopriv_update_counter', 'update_counter');

    Best Regards

Viewing 1 post (of 1 total)

The topic ‘update_sub_field on click of ad image’ is closed to new replies.