Support

Search results for ""

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

Filter dropdown list doesn't reflect CustomField list filter changes

Hi ac team,

I’ve managed to successful use a filter (below) to changed a value ‘id’ in a custom field (I’m using Toolset btw and integration). However these values are not reflected in the filter dropdown list associated with this column. Maybe there is an option button or @param or something I am missing or something that does this.

So I’ve been playing with acp_filter_dropdown_args to try to achieve this but have been able to work out how to set these filter values. The logic I am thinking is:
(Please forgive ignorance, errors etc, not a coder, just being distracted by acPro powers).

Thanks very much.

 
function acp_filter_dropdown_args_course_id( $args, $column, $options ) {

//i would like this change to 'ids' in dropdowns to titles like how it works in the columns using the ac/column/value filter below.

	if ( $column instanceof ACP_Column_CustomField ) {
		$meta_key = $column->get_meta_key(); 
             // This gets the Custom Field key - ?but should this be getting the 'type'?

		if ( 'course_id' === $meta_key ) {
			
                //  the logic is this but how to set the array of options please? 
                //   I can't work out the syntax for setting this array....

	        // for each option in the filtered column
                //	$args['options?/'id'?/value?'][0] => ['get_the_tile($value)'];
		//	$args['options?/'id'?/value'?][1] => ['get_the_tile($value)'];

  		  return $args;
		}
	}
}

===
Successfully got this filter working :)
===

function ac_my_custom_field_column_value_course_id( $value, $id, $column ) {

	if ( $column instanceof ACP_Column_CustomField ) {
		$meta_key = $column->get_meta_key(); // This gets the Custom Field key

		if ( 'course_id' == $meta_key ) {
			// change the value to the tile of the course with the id in this column
			$value = get_the_title($value);
		}
	}

	return $value;
}

add_filter( 'ac/column/value', 'ac_my_custom_field_column_value_course_id', 10, 3 );
6 years, 4 months ago
rob0mitch

I see I should be working with the $options @param in the acp_filter_dropdown_args filter

@type array
$options
Optional. Options for dropdown ([value] => [label])

but still not sure how. Be good to see another example on docs. To see how to implement. ( I knows its php101)

Thanks again

6 years, 4 months ago
rob0mitch

Hi Stefan,

Thanks for taking time on the messenger to help with the snippet for the filter. I have finalised it as:

add_filter( 'acp/filtering/dropdown_args', 'acp_filter_dropdown_args_course_id', 10,2);

function acp_filter_dropdown_args_course_id( $args, $column ) 

	{

		if ( $column instanceof ACP_Column_CustomField ) {

			if ( 'course_id' === $column->get_meta_key() ) {

				foreach ( $args['options'] as $value => $label ) {
					$args['options'][ $value ] = get_the_title( $value );
			}

		}
	}

	return $args;
}

AND IT WORKS PERFECTLY!

THANKS
for quick and clever support.
Still not sure what you did there, but with with some php manuals and reverse engineering, I will understand. Meanwhile it works. Thanks very much.
Best Wishes
Rob

===after-note
Great product also. Surprisingly valuable. Apart from the occassional forays into snippet, hook and filter land, it saves sooooo much time. As per your marketing message. One of those necessary-unnecessary plugins that you only realise you need when you have it.
Cheers

6 years, 4 months ago
Stefan van den Dungen Gronovius
Developer

I’m glad this ticket is solved. I will close this topic

6 years, 4 months ago

You must be logged in to reply to this topic.