I am trying to filter a grid of players based on the clubs they are in. Players and Clubs are both custom page types
Now the Dropdown renders ok on first visit – rendering several teams ok – when the user clicks submit the correct params is added to the query string &dkFLAQueryTeam=5990 – however the Dropdown is now blank…
Any help appreciated
Actions
add_action('restrict_manage_posts', array(DKFLA_PREFIX . 'Players', DKFLA_PREFIX . 'Filters'));
add_filter('parse_query', array(DKFLA_PREFIX . 'Players', DKFLA_PREFIX . 'ParseQuery'));
public function dkFLAFilters()
{
global $typenow, $wp_query, $post;
$type = 'post';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if (DKFLA_PLAYER_POST_TYPE == $type) {
$args = array(
'post_type' => DKFLA_TEAM_POST_TYPE,
'numberposts' => -1,
);
$posts = get_posts($args);
// print_r($args);
// print_r($posts);
?>
<select name="dkFLAQueryTeam">
<option value="0"><?php _e('Filter By ', 'wose45436'); ?></option>
<?php
$current_v = isset($_GET['dkFLAQueryTeam']) ? $_GET['dkFLAQueryTeam']:'';
foreach ($posts as $post) {
printf
(
'<option value="%s"%s>%s</option>',
$post->ID,
$post->ID == $current_v? ' selected="selected"':'',
$post->post_title
);
}
?>
</select>
<?php
}
}
/**
* Submits the custom Filter Dropdown for Custom Posts
*/
public function dkFLAParseQuery($query)
{
global $pagenow;
$type = 'post';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if (DKFLA_PLAYER_POST_TYPE == $type && is_admin() && $pagenow == 'edit.php' && !empty($_GET['dkFLAQueryTeam'])) {
$query->query_vars['meta_key'] = 'dkFLAQueryTeam';
$query->query_vars['meta_value'] = $_GET['dkFLAQueryTeam'];
}
}