• Resolved derlockecom

    (@derlockecom)


    Hello,

    At first I have to thank you for your incredible work! Your plugin is perfect for managing a clients list for a chess club.

    Here’s my problem:
    I’m using Elementor Pro and I want to use a row’s entries (e-mails) to send an e-mail to all of them. The list needs to be comma separated.
    The “to” email field in Elementor can use shortcodes. Looks like I have to create a shortcode which grabs every line of the e-mail row and separate it with a comma.
    I know how to create a shortcode, but it’s unclear for me how to grab the row’s entries. I have to say, I’m not very good with PHP xD
    It would be nice if you can point me in the right direction.

    Code so far:

    function grab_mails(…){
    return ‘…’;
    }
    add_shortcode(‘grabbed_mails’, ‘grab_mails’);`

    Another question would be, if it’s possible to do a check for double entries?

    Thanks and kind regards,
    derlocke

    • This topic was modified 3 years, 11 months ago by derlockecom.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    For this, you can use PHP code like

    $table_id = '123'; // Table ID with the emails.
    $table = TablePress::$model_table->load( $table_id, true, false ); // Load table data, but don't load options or visibility.
    // $table['data'] now contains a two-dimensional array with the table data.
    

    Then, you’d use a foreach loop to extract the relevant cells into an array, and use PHP functions like array_unique() to remove duplicates and implode() to convert the array to a comma-separated list.

    Regards,
    Tobias

    Thread Starter derlockecom

    (@derlockecom)

    Hello again,

    Thank you, for your great answer. It helped a lot and I ended up with this code:

    
    <?php
     function extractEmails($tabledata) {
        $emails = [];
    	$tabledata = array_slice($tabledata, 1);
        foreach ($tabledata as &$entry){
            $emails[] = $entry[2];  # check id in table
        }
        return implode(", ", array_unique($emails));
     }
    
     function extractData($table_id) {
        $table = TablePress::$model_table->load( $table_id, true, false );
        return extractEmails($table['data']);
     }
    
      function grab_mails_user(){
     	return extractData('1');
     }
     add_shortcode("grabbed_mails_user", "grab_mails_user");
    
     function grab_mails_intern(){
        return extractData('2');
     }
     add_shortcode("grabbed_mails_intern", "grab_mails_intern");
    
     ?>

    I hope someone else can use it, too.

    Kind regards,
    derlocke

    • This reply was modified 3 years, 11 months ago by derlockecom.
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    very nice! Yes, that’s pretty much what I had in mind 🙂

    Best wishes,
    Tobias
     
    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

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

The topic ‘Export row to comma-separated list’ is closed to new replies.