• Resolved keygrip

    (@keygrip)


    Hi,

    I am using advanced custom fields and have a field called start_date which is a specific date of a custom post type called “Events”. I used your ‘cac/column/meta/value’ filter in a column called “Event Date” to compare the start_date with today’s date and if the start_date has already past, then I show “Expired” in the column field, otherwise it shows the date of the event. Works great. What I would like to do is create another column that shows the start_date and call it “Start Date” that shows the start_date whether it is past today’s date or not, is there a way to filter the column by label name? Seems that once I modify the start_date custom field using the filter, it changes every time I use it.

    So basically, I want to have two columns that use the same custom field, where one is using the above filter and one is not.

    https://www.ads-software.com/plugins/codepress-admin-columns/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jesper van Engelen

    (@engelen)

    The filter “cac/column/meta/value” passes 3 arguments: $value, $id and $column (in this order). As described in the documentation:

    • $value is the original value which would otherwise be displayed
    • $id will return the ID of the object.
    • $column will return the Admin Columns Column object.

    The column object, $column, holds the unique column ID in $column->properties->name. If you have two custom field columns, one will have “column-meta” as its unique ID, and the other “column-meta-1” — in most cases.

    Even though it’s not a very flexible solution, you can make sure only “Event Date” displays “Expired” if the event date lies in the past by checking the column ID.

    if ( $column->properties->name == '[column ID of the Event Date column]' ) {
    	// Filter value of Event Date column only
    }

    Does this solve your problem?

    Thread Starter keygrip

    (@keygrip)

    Thanks, Jesper. This is actually what I ended up doing and works great for what I needed.

    Plugin Author Jesper van Engelen

    (@engelen)

    I’m glad to hear that. We’ll consider adding this to the documentation as well.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Two columns with the same custom field’ is closed to new replies.