Query Posts based upon options selected in a Category Dropdown
-
I’m creating a plugin that will only be used in the wordpress admin, not on the front site of the site.
I’ve created a custom post type called “sports_players”
I’ve also created several custom taxonomies that are only used with that custom post type, for example: “player_age”, “player_sport”, “player_sport_level”
There’s also a metabox that holds the “player_id”.What I want to do is get a list of all of the sports listed in “player_sport” (example: football, baseball, basketball, etc) and put them in a dropdown box. Which I have been able to do in several ways, but this is the code I’m using at the moment for that
<div class="wrap"> <h2><?php _e( 'Select A Sport' ); ?></h2> <form id="ar-sport-form" action="" method="POST"> <div> <?php $args = array( 'show_option_none' => __( 'Select A Sport' ), 'show_count' => 0, 'orderby' => 'name', 'echo' => 0, 'taxonomy' => 'sports_roster_category', ); ?> <?php $select = wp_dropdown_categories( $args ); ?> <?php $replace = "<select$1 onchange='return this.form.submit()'>"; ?> <?php $select = preg_replace( '#<select([^>]*)>#', $replace, $select ); ?> <?php echo $select; ?> <noscript> <input type="submit" name="ar-roster-submit" value="<?php _e('Get Results', 'athletic-roster'); ?>"/> </noscript> </div> </form> </div><!-- .wrap -->
When someone selects one of the sports from the drop down, using AJAX I want to display a table that shows all of the posts from the sports_player custom post type, along with all of the custom taxonomies and meta data associated with that post entry.
What I need help with at the moment is trying to figure out how to get all of the data from the posts associated with the selected custom post taxonomy.
Also, I need to accomplish this without installing any additional plugins.
Any help would be greatly appreciated.
Thanks
- The topic ‘Query Posts based upon options selected in a Category Dropdown’ is closed to new replies.