Community Forums › Forums › Archived Forums › Design Tips and Tricks › Modify Search Function
Tagged: agent press search
- This topic has 3 replies, 2 voices, and was last updated 8 years, 7 months ago by brent s.
-
AuthorPosts
-
September 4, 2015 at 1:21 pm #164603brent sMember
I have asked a similar question and I need a little more guidance. I have modified the search code as shown below. Essentially, I took this line of code and the bolded language used to be "hidden" now I have made it "textbox." and a textbox appears. When I run a search based on registered taxonomies, it works with some taxonomies, but not another. Of course, I need the one not being searched. What else do I modify to search a specific registered taxonomy?
echo '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" ><input type="<strong>textbox</strong>" value="" name="s" /><input type="hidden" value="listing" name="post_type" />';
<?php /** * This widget presents a search widget which uses listings' taxonomy for search fields. * * @package AgentPress * @since 2.0 * @author Ron Rennick */ class AgentPress_Listings_Search_Widget extends WP_Widget { function __construct() { $widget_ops = array( 'classname' => 'property-search', 'description' => __( 'Display property search dropdown', 'agentpress-listings' ) ); $control_ops = array( 'width' => 200, 'height' => 250, 'id_base' => 'property-search' ); parent::__construct( 'property-search', __( 'AgentPress - Listing Search', 'agentpress-listings' ), $widget_ops, $control_ops ); } function widget( $args, $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'button_text' => __( 'Search Properties', 'agentpress-listings' ) ) ); global $_agentpress_taxonomies; $listings_taxonomies = $_agentpress_taxonomies->get_taxonomies(); extract( $args ); echo $before_widget; if ( $instance['title'] ) echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; echo '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" ><input type="<strong>textbox</strong>" value="" name="s" /><input type="hidden" value="listing" name="post_type" />'; foreach ( $listings_taxonomies as $tax => $data ) { if ( ! isset( $instance[$tax] ) || ! $instance[$tax] ) continue; $terms = get_terms( $tax, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => 100, 'hierarchical' => false ) ); if ( empty( $terms ) ) continue; $current = ! empty( $wp_query->query_vars[$tax] ) ? $wp_query->query_vars[$tax] : ''; echo "<select name='$tax' id='$tax' class='agentpress-taxonomy'>\n\t"; echo '<option value="" ' . selected( $current == '', true, false ) . ">{$data['labels']['name']}</option>\n"; foreach ( (array) $terms as $term ) echo "\t<option value='{$term->slug}' " . selected( $current, $term->slug, false ) . ">{$term->name}</option>\n"; echo '</select>'; } echo '<input type="submit" id="searchsubmit" class="searchsubmit" value="'. esc_attr( $instance['button_text'] ) .'" /> <div class="clear"></div> </form>'; echo $after_widget; } function update( $new_instance, $old_instance ) { return $new_instance; } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'button_text' => __( 'Search Properties', 'agentpress-listings' ) ) ); global $_agentpress_taxonomies; $listings_taxonomies = $_agentpress_taxonomies->get_taxonomies(); $new_widget = empty( $instance ); printf( '<p><label for="%s">%s</label><input type="text" id="%s" name="%s" value="%s" style="%s" /></p>', $this->get_field_id( 'title' ), __( 'Title:', 'agentpress-listings' ), $this->get_field_id( 'title' ), $this->get_field_name( 'title' ), esc_attr( $instance['title'] ), 'width: 95%;' ); ?> <h5><?php _e( 'Include these taxonomies in the search widget', 'agentpress-listings' ); ?></h5> <?php foreach ( (array) $listings_taxonomies as $tax => $data ) { $terms = get_terms( $tax ); if ( empty( $terms ) ) continue; $checked = isset( $instance[ $tax ] ) && $instance[ $tax ]; printf( '<p><label><input id="%s" type="checkbox" name="%s" value="1" %s />%s</label></p>', $this->get_field_id( 'tax' ), $this->get_field_name( $tax ), checked( 1, $checked, 0 ), esc_html( $data['labels']['name'] ) ); } printf( '<p><label for="%s">%s</label><input type="text" id="%s" name="%s" value="%s" style="%s" /></p>', $this->get_field_id( 'button_text' ), __( 'Button Text:', 'agentpress-listings' ), $this->get_field_id( 'button_text' ), $this->get_field_name( 'button_text' ), esc_attr( $instance['button_text'] ), 'width: 95%;' ); } }
September 4, 2015 at 3:53 pm #164616brent sMemberI have resolved this and figured out how to make it work.
September 6, 2015 at 11:16 am #164755TomParticipantPerhaps you could share your solution with the forum and mark your thread "resolved"?
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]September 6, 2015 at 12:25 pm #164757brent sMemberSorry, I didn't realize to do that. I installed search everything plugin and made the search selections in the plugin.
-
AuthorPosts
- The topic ‘Modify Search Function’ is closed to new replies.