• Resolved Anonymous User 13716511

    (@anonymized-13716511)


    I would like to use this plugin in a template file.
    I’ve created a table, id=3. With column names.
    I would like to populate the data on the table using php in the template file, pulling data from acf fields in a custom post type.
    Is this possible using this plugin?

    I tried to find a starting point and used the following code but nothing appeared on the table.

    $table_id = '3';
    $table = TablePress::$model_table->load( $table_id );
    $table['data'][0][0] = 'hello'; 

    What is the best way to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    To be honest, I don’t really recommend this. Your best chance probably is to use the tablepress_table_render_data filter hook (see https://github.com/TobiasBg/TablePress/blob/master/classes/class-render.php#L258) and to overwrite the data there.

    Regards,
    Tobias

    Thread Starter Anonymous User 13716511

    (@anonymized-13716511)

    How would I use this hook?
    I tried
    function therapist_listing_content(){
    echo “populate cells?”;
    }
    add_action(‘therapist_listing_content’, ‘tablepress_table_render_data’);
    but it isn’t doing anything. How do I connect it to table id =3

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    I recommend that you first try to learn more about how filters work in WordPress.

    Basically, the filter will get the current table data as a parameter, you can then modify it and return the new data.

    For example, use this:

    add_filter( 'tablepress_table_render_data', 'LucyTech_modify_TablePress_table', 10, 2 );
    function LucyTech_modify_TablePress_table( $table, $render_options ) {
      if ( '3' !== $table['id'] ) {
        return $table;
      }
    
      // modify $table['data'] here
    
      return $table;
    }

    Regards,
    Tobias

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘dynamically populate cell contect’ is closed to new replies.