Support

Search results for ""

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

Filter dropdown options by post status

Hi.

I want to filter the available dropdown options for a meta field ONLY to the available values for custom posts that have a specific post status.

At the moment, all values for all the different post status are show. How can I exclude the values that come from posts with a specific status?

EXAMPLE:

Custom Post 1 – Post Status “Sold” – Brand: VW
Custom Post 2 – Post Status “Sold” – Brand: BWM
Custom Post 4 – Post Status “Sold” – Brand: Audi
Custom Post 5 – Post Status “Open” – Brand: Ford
Custom Post 6 – Post Status “Open” – Brand: Tesla

Normally all 5 Car Brands are shown in the filter, but I want to exclude all the “Sold” ones in the filter list.

How do I do it?

– Daniel

7 years, 11 months ago
Tobias Schutter
Developer

Hi Daniel,

You can alter the dropdown options by using cac/addon/filtering/options.

Here is a full working example for your case:


function ac_filter_post_status_example( $options, $column ) {
	if ( 'column-status' === $column->get_type() ) {
		if ( $options ) {
			foreach ( $options as $k => $v ) {
				if ( false !== strpos( $v, 'Sold' ) ) {
					unset( $options[ $k ] );
				}
			}
		}
	}

	return $options;
}
add_filter( 'cac/addon/filtering/options', 'ac_filter_post_status_example', 10, 2 );
7 years, 11 months ago
Daniel

Hi.

Thank you for the fast response. But I’m not quite sure if you understand the problem 100%.

I want to filter column-meta (Brand) based on post status. In other words: If the brand meta value belongs to a post with status “sold”, dont’t show it.

I don’t want to filter the post status by itself.

– Daniel

7 years, 11 months ago
Tobias Schutter
Developer

Ah, I have misunderstood your question :)

Unfortunately filtering on only non “Sold” items is not possible, only on an individual post status.

A way to solve this would be to introduce an extra taxonomy called “Brand” and add the terms BMW, Audi etc. Then have the post status only list “Sold” and “Open”. This would allow you to add two filtering menu’s, one with the brands and one with sold status, which you can use to filter on “Open” cars and then make a further selection by using the “Brand” filter menu.

7 years, 11 months ago

You must be logged in to reply to this topic.