I would like to delete row from front end. This is what i did :


<?php $row = get_row_index(); ?>
<tr data-rownum="'. $row .'">
    <span class="deletecontrat iconfont_d" data-toggle="tooltip" data-placement="right" title="Effacer ?">r</span>


jQuery( document ).on( 'click', '.deletecontrat', function() {

    $rownumjs = $(this).parent().parent().data("rownum");

                'action': 'mon_action',
                'param': $rownumjs



function add_js_scripts() {
    wp_enqueue_script( 'script', get_template_directory_uri().'/custom/js/ajax.js', array('jquery'), '1.0', true );
    wp_localize_script('script', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
add_action('wp_enqueue_scripts', 'add_js_scripts');

function mon_action() {

    $param = $_POST['param'];

    delete_row("field_5c8fa4201b65f", 1, $post_id);

    echo $param;
add_action( 'wp_ajax_mon_action', 'mon_action' );
add_action( 'wp_ajax_nopriv_mon_action', 'mon_action' );

So in my console i get response :

  • 1 for the first row
  • 2 for the second row

and so on…

I assume that my code working, but now i can't or i don't know how to execute my delete function… I have read this, but nothing happen.

What am i doing wrong ?

(I hope i'm cristal clear because english is not my language.)


You have 1 hardcoded as the row number in mon_action().

It should be delete_row( 'field_5c8fa4201b65f', (int) $_POST['param'], $post_id );

  • Hum yes but it was for a test and i've tried with delete_row( 'field_5c8fa4201b65f', $param, $post_id ); It doesn't work either
    – Fluti
    Apr 22 '19 at 18:58
  • How are you getting $post_id? Apr 22 '19 at 19:02
  • But just with function mon_action() { echo "<script>console.log('the message function is called');</script>"; die(); } i have no response in ma console log
    – Fluti
    Apr 23 '19 at 11:50
  • That wouldn't work as you're expecting it to. The rest of your code works fine. Apr 23 '19 at 13:21

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.