Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ddesmond

    (@ddesmond)

    Hello again,

    I have one more idea. I am hoping you can assist if possible.

    All of my documents are organised into parent child subfolders e.g.

    – Movies
    — 2022
    — 2023
    — 2024

    Could we add a “Subfolder” column to the document gallery? This would solve my problem and also eliminate the need for a custom field and save me from entering the subfolder information for each media file individually.

    Thanks!

    Thread Starter ddesmond

    (@ddesmond)

    Thanks so much for getting back to me, I appreciate it. Below is my code. It is a modified version of the working code you supplied. However, I may not have updated it incorrectly:

    // The hook used to add a new column
    add_filter("catf_dg_columns", "catf_dg_add_column", 10, 1);

    /**
    * Add a new column
    *
    * @param array $columns An array used to define label and key of column
    * @return array
    */
    function catf_dg_add_column($columns)
    {
    // Add label and key for new column here
    $columns[] = [
    "label" => __("Test Field", "catfolders-document-gallery"),
    "key" => "test_field",
    ];
    return $columns;
    }

    // The hook used to add content of column
    add_filter("catf_dg_columns_html", "catf_dg_add_column_html", 10, 3);

    /**
    * Add content of columns
    *
    * @param array $columns Label and key of column
    * @param array $file Info of file
    * @param array $attr Attributes of table
    * @return array
    */
    function catf_dg_add_column_html($columns, $file, $attr)
    {
    $id = get_the_ID();
    $test_field_value = get_field("test_field", $id);

    // Content of column
    if ("test_field" === $columns["key"]) { ?>
    <td>
    <div class=""><?php echo esc_html($test_field_value); ?></div>
    </td>
    <?php }
    return $columns;
    }

    What I am trying to do is add an extra column that contains the value of an Advanced Custom Field (named test_field in this case).

    Adding custom fields to the document gallery would be an incredibly useful feature! I have a significant number of documents tagged with custom fields. Being able to display and sort by these values would greatly enhance this plugin!

    Thanks again

    Thread Starter ddesmond

    (@ddesmond)

    Thank you this worked perfectly and shows the user name!

    I’m hoping to extend this code to display the value of a custom field I’ve added to my media files using ACF. The field will contain a year value (2020, 2021, 2022, etc).

    For this example I’ve created a custom field named test_field, and modified your code but the column remains empty. Could you please assist me?

    // The hook used to add a new column
    add_filter("catf_dg_columns", "catf_dg_add_column", 10, 1);

    /**
    * Add a new column
    *
    * @param array $columns An array used to define label and key of column
    * @return array
    */
    function catf_dg_add_column($columns)
    {
    // Add label and key for new column here
    $columns[] = [
    "label" => __("Test Field", "catfolders-document-gallery"),
    "key" => "test_field",
    ];
    return $columns;
    }

    // The hook used to add content of column
    add_filter("catf_dg_columns_html", "catf_dg_add_column_html", 10, 3);

    /**
    * Add content of columns
    *
    * @param array $columns Label and key of column
    * @param array $file Info of file
    * @param array $attr Attributes of table
    * @return array
    */
    function catf_dg_add_column_html($columns, $file, $attr)
    {
    $id = get_the_ID();
    $test_field_value = get_field("test_field", $id);

    // Content of column
    if ("test_field" === $columns["key"]) { ?>
    <td>
    <div class=""><?php echo esc_html($test_field_value); ?></div>
    </td>
    <?php }
    return $columns;
    }

    Thank you!!

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