I’ve used Advanced Custom Fields to create custom fields for Competition name, answers etc. I’ve made a custom post type for competitions as shown on the image and I used WordPress functions.php to create the columns from my custom fields values.
I’m trying to get a “Filter by”-dropdown box with the competitions different names/labels like shown below, but I can only find solutions using taxonomies, which I rather not use if possible because I’ve only used custom fields for everything else.
Is it possible to make a custom “Filter by” dropdown using only custom fields?
And for displaying result for Filter then try this code
add_filter( 'parse_query', 'prefix_parse_filter' );
function prefix_parse_filter($query) {
global $pagenow;
$current_page = isset( $_GET['post_type'] ) ? $_GET['post_type'] : '';
if ( is_admin() &&
'competition' == $current_page &&
'edit.php' == $pagenow &&
isset( $_GET['competition-name'] ) &&
$_GET['competition-name'] != '' ) {
$competition_name = $_GET['competition-name'];
$query->query_vars['meta_key'] = 'competition_name';
$query->query_vars['meta_value'] = $competition_name;
$query->query_vars['meta_compare'] = '=';
}
}
Change the meta key and meta value as required.
I have taken “competition name as meta_key and “competition-name” as select drop down name.