Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Keith

Problems with ac/headings/label

Hello…

Great plugin! I am starting to give deeper into the actions/filters and am having an issue.

I want to alter the label with code. I assume this is the filter to use: ac/headings/label

When I use it, I am able to edit $label directly… but I want it to be conditional based on the $column.
First… is this an ‘action’ or a ‘filter’? I see here in the docs to use: add_action but when I look in the code I see: apply_filters

At any rate, I tried both, and when I reference $column I get a blank screen on the Posts Listing page.

Here’s my test code that I placed in a custom function:


function cc_ac_column_heading_label( $label, $column ) {
if ( 'column-acf_field' == $column->get_type() ) {
$acf_key = $column->get_setting( 'field' )->get_value(); // Gets the stored ACF key for the stored column
if ( 'field_59b3fa2f8934b' == $acf_key ) {
$label = "V";
}
}
return $label;
}
add_filter( 'ac/headings/label', 'cc_ac_column_heading_label' );

Any suggestions? Thanks!

4 years ago
Keith

p.s. I meant to say in a ‘Custom Plugin’ not ‘Custom Function’
… and, not sure why my name is showing up as ‘Amy’ :)

4 years ago
Keith

Figured it out…

Forgot to do this:

add_filter( 'ac/headings/label', 'cc_ac_column_heading_label', 10, 2 );

4 years ago
Stefan
Developer

Hi Keith,

Thanks for your feedback.

1) I’ve changed your username
2) Great you figured it out. It indeed should be a filter and I’ve changed the documentation.
Checking the column for an instance might be better since you can also use a method to get the ACF key (hash). Have a look at the following snippet. Maybe it will help you to improve the function you already have.

/**
 * @param string $label
 * @param AC_Column $column
 *
 * @return string
 */
function cc_ac_column_heading_label( $label, $column ) {

	if ( $column instanceof ACA_ACF_Column) {

		if ( 'field_59b3fa2f8934b' === $column->get_field_hash() ) {

			$label = "V";

		}

	}

	return $label;

}

add_filter( 'ac/headings/label', 'cc_ac_column_heading_label', 10, 2 );
4 years ago
Keith

Perfect, thanks!

4 years ago

You must be logged in to reply to this topic.