Include WPFTS in custom search function
-
Hi there!
I am using a custom search function to only display images when using a search form.
Unfortunately I don’t know how to use the plugins index within my search function.
This is what I have in my functions.php:
add_action('pre_get_posts', 'attachment_search'); function attachment_search( $query ) { if ($query->is_search) { $query->set( 'post_type', array( 'post', 'attachment' ) ); $query->set( 'post_status', array( 'publish', 'inherit' ) ); $query->set( 'posts_per_page', 1000); } return $query; }
This is what I have in my search.php:
<div id="content" class="content" role="main"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $a[] = get_the_ID(); endwhile; $ids_comma = implode( ",", $a ); echo do_shortcode('[vc_row full_width="stretch_row_content"][vc_column][dt_gallery_masonry bwb_columns="desktop:5|h_tablet:4|v_tablet:3|phone:2" image_border_radius="0px" project_icon_color="#ffffff" project_icon_border_width="0px" include="'.$ids_comma.'" loading_mode="js_pagination" jsp_posts_per_page="60" jsp_show_all_pages="y" jsp_gap_before_pagination="16px"][/vc_column][/vc_row]'); ?> <?php else : get_template_part( 'no-results', 'search' ); endif; ?> </div>
Sometimes there are over 1000 attachments to show so my current search function takes about 10 to 15 seconds to get all the image ID’s :/
I would really appreciate your help!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Include WPFTS in custom search function’ is closed to new replies.