• Resolved wordpressorgpublic

    (@wordpressorgpublic)


    Hi.
    I was wondering if you would be so kind to give an example (similar to the from_date https://www.ads-software.com/support/topic/url-variables/#post-10684492) just using a GF field value. Creating a link to download only the rows where GF1 filed 33 value number = current post ID.

    Thank you.

    <?php
    // functions.php

    /**
    * Filtering rows example ?workshop_id={workshop}
    * Include row by default, but exclude based on a certain condition
    * In this case we exclude every row where $workshop value does not equal current post ID
    * And we take $workshop value from the GF 1 filed 33
    */

    add_filter(‘gfexcel_output_rows’, function ($rows) {
    if (!array_key_exists(‘workshop_id’, $_GET)) {
    return $rows; // nothing to filter
    }

    $workshop_id =

    ??????????

    return $rows; //include this row by default
    });
    });

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Doeke Norg

    (@doekenorg)

    hi @wordpressorgpublic,

    Sure I’d love to help. But in order for this to work, you need to have a field in your form that contains the workshop_id. Can you provide the ID of that field?

    I’ll try to find some time later in the day to provide the example.

    Plugin Author Doeke Norg

    (@doekenorg)

    Hi @wordpressorgpublic,

    I have small example, but I found it’s not really user-friendly. So I added an enhancement on the roadmap to add more info the value object, so we can know more easily what column we filter against. And maybe, I’ll try and add some easier filter-function in the future. But I need to make that a less abstract idea ??

    For now you’ll have to use something like this:

    add_filter('gfexcel_output_rows', function ($rows) {
        if (!array_key_exists('workshop_id', $_GET)) {
            return $rows; // nothing to filter
        }
    
        return array_filter($rows, function ($row) {
            // $row is an array with every column, starting at 0. So if you know column 4 has the ID, you use $row[3].
            // Just count the columns and subtract 1. This example is assuming column 4 has the info.
            // 'strval' is needed (for now) because the value of the row is most likely a value object, and not a string.
            return strval($row[3]) === strval($_GET['workshop_id']);
        });
    });

    I hope this helps you out.

    • This reply was modified 6 years, 4 months ago by Doeke Norg. Reason: Smaller example
    Thread Starter wordpressorgpublic

    (@wordpressorgpublic)

    Hi Doeke, it WORKS ??
    wow, I am so appreciative, and impressed. Not just with the great plugin you created, but the incredible support and willingness to help.
    Thank you again.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Filter with link – URL Variables using array_filter’ is closed to new replies.