Support

Search results for ""

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

Add filtering for Custom Column

Hi,

I downloaded the starter kit to add a custom column on custom post type overview.
The returned value is the post count of a WP Query:

[code]
public function get_raw_value($post_id) {

// put all the column logic here to retrieve the value you need
// For example: $value = get_post_meta( $post_id, '_my_custom_field_example', true );

$academicYear = academicYear();

$args = array(
'numberposts' => -1,
'post_type' => 'erp_gdp',
'meta_query' => array(
array(
'key' => 'gdp_eleve',
'compare' => '=',
'value' => $post_id
),
array(
'key' => 'gdp_annee_academique',
'compare' => '=',
'value' => $academicYear
)
)
);
$query = new WP_Query($args);

$value = $query->post_count;

return $value;
}
[/code]

Currently, the column displays the number of services for each members form the current academic year (2018-2019).
Each service is associated to a member and an academic year.

I would like to add a filering dropdown for this custom column to display the number of services from another academic year. (eg. 2017-2018) and change the returned value of get_raw_value function.

I find this post :

Add filtering for Custom Column

but no solution for my situation.

Thanks for your answer.

Tom

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

Hi Tom,

Let me try to understand your use case.

1) You have a column that shows you the number of services for a date range (default 2018-2019)
2) You want to use the ACF filtering logic to alter the display of this column based on the filtered value.

Please notice that our filtering logic is meant to alter the result set on the page. What you want is to alter the value of a cell, which is not the expected behavior of our filtering logic. The overview page results would not be affected by the filtering action so I would not advise doing that.

Instead, you could create a separate link somewhere on the overview that adds a param to the URL that you pick up in your get_raw_value method. You could for example work with a param ‘academic_year’ that is by default the current year.

But if you want to continue using our filtering method, then you should have a look on our default columns how we do that. Since this is a bit more complex to add to custom columns, we did not have any documentation for it, nor is it implemented in our toolkit. What you want to do is to create a new Filtering Model that allows you to set the drop down options and the filtering logic. In your case, there will be no filtering logic, since you want to alter the value of your column based on the params in the URL. Please notice that all values in the URL are base encoded so you have to decode it, if you want to use it in your column.

5 years, 6 months ago

You must be logged in to reply to this topic.