Contents

Bp_Search_Posts::print_search_options( $items_to_search )

What taxonomy should be searched on? Should search on the Post Meta?

Description

Prints options to search through all registered taxonomies with give post type e.g $this->cpt_name

Print options to search through Post Meta

Source

File: bp-search/classes/class-bp-search-posts.php

		function print_search_options( $items_to_search ){
			global $wp_taxonomies;
			echo "<div class='wp-posts-fields' style='margin: 10px 0 10px 30px'>";

			/**  Post Meta Field **********************************/

			$label 		= sprintf( __('%s Meta', 'buddyboss' ), ucfirst( $this->pt_name ) );
			$item 		= 'post_field_' . $this->pt_name.'_meta';
			$checked 	= ! empty( $items_to_search ) && in_array( $item, $items_to_search ) ? ' checked' : '';

			echo "<label><input type='checkbox' value='{$item}' name='bp_search_plugin_options[items-to-search][]' {$checked}>{$label}</label><br>";

			/** Post Taxonomies Fields *********************************/
			$pt_taxonomy = get_object_taxonomies( $this->pt_name ) ;

			foreach ( $pt_taxonomy as $tax ) {

				$label 		= ucwords( str_replace( '_', ' ', $tax ) );
				$value 		= $this->search_type.'-tax-'.$tax;
				$checked 	= !empty( $items_to_search ) && in_array( $value, $items_to_search ) ? ' checked' : '';

				echo "<label><input type='checkbox' value='{$value}' name='bp_search_plugin_options[items-to-search][]' {$checked}>{$label}</label><br>";
			}

			echo "</div><!-- .wp-user-fields -->";
		}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.