Commits

ncrocfer committed 47b813f

Added the search form

Comments (0)

Files changed (4)

includes/bp-portfolio-classes.php

                 'url' => null,
                 'created_at' => date( 'Y-m-d H:i:s' ),
                 'updated_at' => date( 'Y-m-d H:i:s' ),
-                'tags' => array()
+                'tags' => array(),
+                'search_terms' => null
             );
 
             $r = wp_parse_args( $args, $defaults );
                     $query_args['author'] = $author_id;
             }
             
+            // Filter by search terms
+            if ( isset($search_terms) AND ($search_terms != bp_get_search_default_text( 'portfolio' ))) {
+                $query_args['s'] = $search_terms;
+            }
+            
             $this->query = new WP_Query( $query_args );
 
             // Set up some pagination

includes/bp-portfolio-template.php

                     'updated_at' => date( 'Y-m-d H:i:s' ),
                     'tags' => array(),
                     'posts_per_page'	=> 10,
-                    'page'	=> 1
+                    'page'	=> 1,
+                    'search_terms' => null
                 );
                 
 		$r = wp_parse_args( $args, $defaults );
             return get_the_author_ID();
     }
 
+    
+/**
+ * Echo the search form
+ */
+function bp_portfolio_projects_search_form() {
+	global $bp;
+
+	$default_search_value = bp_get_search_default_text( 'portfolio' );
+	$search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
+
+	<form action="" method="get" id="search-projects-form">
+		<label><input type="text" name="s" id="projects_search" value="<?php echo esc_attr( $search_value ) ?>"  onfocus="if (this.value == '<?php echo $default_search_value ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php echo $default_search_value ?>';}" /></label>
+		<input type="submit" id="projects_search_submit" name="projects_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
+	</form>
+
+<?php
+}
+    
 
 ?>

templates/default/index.php

 
                     <h3><?php _e('Projects directory', 'bp-portfolio'); ?></h3>
                     
+                    <?php do_action( 'bp_before_directory_groups_content' ); ?>
+
+                    <div id="projects-dir-search" class="dir-search" role="search">
+
+                            <?php bp_portfolio_projects_search_form() ?>
+
+                    </div>
+
+                    
                     <?php do_action( 'template_notices' ); ?>
 
 			<div class="item-list-tabs" role="navigation">

templates/default/projects-loop.php

+<?php //print_r(bp_ajax_querystring( 'projects' ));?>
 <?php if(bp_portfolio_has_items( bp_ajax_querystring( 'projects' ) )) :?>
     <div id="pag-top" class="pagination">