Public Ticket #1673444
Do you have any examples of wpdatatables_filter_cell_val in use?


  • hulabula started the conversation


    I'm using ACFs and wpDataTables - so far it's been great!  I would however like to process some data within the cells when they're rendered as a table.

    For example, I have a bi-driectional between ACFs that are stored in the table as a comma delimited string of PostIDs, e.g. "[1,2,3]"

    I want to render them in the table column as linked buttons in the column to those post, e.g. "<Post 1> <Post 2> <Post 3>"

    I believe that wpdatatables_filter_cell_val will do the trick, but I would love to see an example of it in action as I'm having so troubles getting it to work.  I've googled and googled and it doesn't look like anyone has posted any examples of it in action. Can you provide one?


  • hulabula replied

    I've been tinkering and I got it *sort of* working, and so I'd like some advice as wpdatatables_filter_cell_val is not behaving as I think it should be according to the documentation.

    Here's the working code from my function file:

    function fun_fun_function( $val ){
         if(preg_match("/\[([0-9\,]*)\]/", $val)){
             $val_return_string = "";
             $val = str_replace("[", "", $val);
             $val = str_replace("]", "", $val);
             $val_array = explode(",", $val);
             foreach($val_array as $val_piece){
                 $val_return_string = '<a href="#LINK_URL?id='.$val_piece.'" class="value_button">'.$val_piece.'</a> ';
         return $val_return_string;
     return $val;
    add_filter('wpdatatables_filter_cell_val','fun_fun_function', 9);

    This tests each column for the string format I'm looking for, "[1,2,3]", and then cleans it up. Removes the brackets, explodes on the comma, adds a href to each id, and then returns it as a string.  The result is what I'm looking for, a column full of links to URLs with the ids.

    Now for the current problem...

    I would like to test the tableID to see which table that the cell is being passed to the function so that I can add custom returns.  I think I should be able to do this because the document looks like it does...


    wpdatatables_filter_cell_val( $val, $tableId )
    This filter is applied to the value of the cell before it is returned to the front-end. 

    $val is the cell value 

    $tableId is the table identifier from the MySQL table (wp_wpdatatables).


    But when I add the $tableId to my function, like so....

    function fun_fun_function( $val, $tableId ){

     it breaks the table render and nothing but the headers are displayed.

    In an ideal world I would like to pass along the tableId and the columnName so that I don't have to test each cell value to see if it's the value I want to process further and then also apply additional custom processes for each column and/or table.

    The code at line 617 in class.wpdatacolumn.php looks like it should pass the $tableID to wpdatatables_filter_cell_val just fine, but it's breaking the render when I add it to my function.  I've tried replacing $this->getParentTable()->getWpId() with a simple true to see if that would pass, but again, it ends up breaking the table render.

    public function returnCellValue($cellContent) {
        $cellValue = $this->prepareCellOutput($cellContent);
        $cellValue = apply_filters('wpdatatables_filter_cell_val', $cellValue, $this->getParentTable()->getWpId());
        return $cellValue;


  •  394
    Milan replied

    Hi hulabula,
    Thank you for your purchase.

    Sorry for late response. 

    We are located in Serbia and our working time is from 10:00 to 17:00 CET. business days.

    Filters and Actions are built for developers and please note that using hooks requires certain level of programing skills and included support refers only to advices,  at the moment we don't have examples for using it and it is beyond of scope of support that we provide.

    About the issue that you have with this hook is because you didn't pass number of arguments that this filter accept. One fundamental argument that is easy to miss is specifying the number of arguments. Most filters have only one argument and so people drop the argument from add_filter.

    So if you add this

    add_filter('wpdatatables_filter_string_cell','fun_fun_function', 9 , 2);

    and insert table id in your function filter will work correctly.

    You also have option to filter by column type for example wpdatatables_filter_date_cell, wpdatatables_filter_datetime_cell, wpdatatables_filter_string_cell....

    Best regards.

    Check out our documentation for Amelia - WordPress booking plugin on this link.

    Check out our documentation for wpDataTables - WordPress table plugin on this link.

    Kind Regards,
    MIlan Jovanovic

  • hulabula replied

    ::facepalm:: I totally missed the accepted_args argument. Thank you for pointing that one out!  :)

  •  394
    Milan replied

    Hi hulabula,

    You are welcome.  Glad that we help you with this issue.

    If you have any more issues or questions feel free to open a new ticket, we will gladly help.

    We'd greatly appreciate it if you could take a minute and leave a Review on CodeCanyon on this link. Thanks! 

    Check out our documentation for Amelia - WordPress booking plugin on this link.

    Check out our documentation for wpDataTables - WordPress table plugin on this link.

    Kind Regards,
    MIlan Jovanovic