Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLiam Mitchell-Dolby
5,666 PointsI'm trying to create a custom search form on my Wordpress site that only searches a particular custom post type.
Essentially on my website I have a Meet the Team page that displays all team members on the page. The team members are a custom post type called "staff". I want to build a search form on the page that narrows the team list by name or category, but I can't get the search form to only display results from the custom post type.
I've tried several tutorials I've found online but none of the solutions work! I can't resolve this problem. Can anyone help? Has anyone had this problem?
Liam Mitchell-Dolby
5,666 PointsForm so far looks like this: <form id="team-search" role="team-search" method="get" class="topbttmpadding" action="<?php echo get_permalink( '/' ); ?>"> <label> <span class="offscreen"><?php echo x( 'Category:', 'label' ) ?></span> <?php $swp_cat_dropdown_args = array( 'show_option_all' => _( 'Any Service' ), 'name' => 'cat', 'exclude' => 1, ); wp_dropdown_categories( $swp_cat_dropdown_args ); ?> </label> <label> <span class="offscreen"><?php echo _x( 'Name search:', 'label' ) ?></span> <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search', 'placeholder' ) ?>" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" /> </label> <input type="image" alt="Submit search query" src="<?php echo get_template_directory_uri(); ?>/img/search-icon.png"> <input type="hidden" value="staff" name="post_type" id="post_type" /> </form>
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 PointsWhat code have you written so far?