BP_Search_CPT::generate_html( $template_type = '' )

Description

Source

File: bp-search/plugins/search-cpt/class-bp-search-cpt.php

		protected function generate_html( $template_type='' ){
			$post_ids = array();
			foreach( $this->search_results['items'] as $item_id=>$item_html ){
				$post_ids[] = $item_id;
			}

			//now we have all the posts
			//lets do a wp_query and generate html for all posts
			$qry      = new WP_Query( array( 'post_type' => $this->cpt_name, 'post__in' => $post_ids ) );
			$template = bp_locate_template( "search/loop/{$this->cpt_name}.php" ) ? "loop/{$this->cpt_name}" : 'loop/post';

			if( $qry->have_posts() ){
				while( $qry->have_posts() ){
					$qry->the_post();
					$result = array(
						'id'	=> get_the_ID(),
						'type'	=> $this->search_type,
						'title'	=> get_the_title(),
						'html'	=> bp_search_buffer_template_part( $template, $template_type, false ),
					);

					$this->search_results['items'][get_the_ID()] = $result;
				}
			}
			wp_reset_postdata();
		}

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.