Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'];
    }
}
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.