Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1001788

    Hello there!

    I saw a few other forum posts about using Relevanssi or another plugin to customize search options for a worpdress site but i could not find a solid answer…

    I am trying to create a search of Portfolio Items (not Posts) on my client’s site. They would like to be able to enter keywords in a search bar and return any portfolio items that match those… pretty straight forward but I am not sure how to implement the search option on portfolio items.

    What steps are needed to change the databse query from posts to portfolio?

    Thanks for the help!

    #1001819

    Hey FZKFranziska,

    You can use this code to limit the ajax search to portfolio items:

    
    add_filter('avf_ajax_search_query', 'avf_ajax_search_query_mod', 10, 1);
    function avf_ajax_search_query_mod( $search_parameters )
    {
    	$defaults = array('numberposts' => 5, 'post_type' => 'portfolio', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false, 'results_hide_fields' => '');
    	$_REQUEST['s'] = apply_filters( 'get_search_query', $_REQUEST['s']);
    	$search_parameters = array_merge( $defaults, $_REQUEST );
    	return $search_parameters;
    }
    

    Add it to the child theme functions.php (i.e. at the very bottom of the file).

    Best regards,
    Dude

    #1001957

    Hey Dude!

    Thank you for the code snippet :-)

    Is there anything else I need to do to implement this portfolio search other than add that to the functions.php file?

    I added the code and inserted a Search Widget on a page to test it out but do not get any results when I search for the names of specific portfolio items or the categories or tags set up for the portfolio items.

    Thanks!

    #1001979

    Hey!

    This code will only work with the default Enfold search form (click on the search icon in the main menu to activate the Enfold search field). This code won’t affect the standard wordpress search or the wordpress search widget. If you want more control over the wordpress search please install a plugin like relevanssi ( https://wordpress.org/plugins/relevanssi/ ). You can then activate Relevanssi for the Enfold ajax search too ( https://kriesi.at/support/topic/is-there-a-searchbar-working-togehter-with-woocommerce/#post-990568 ).

    Cheers!
    Peter

    #1002012

    Awesome!

    I got the search up and going with your code snippets… thank you for those I am pretty green when it comes to writing PHP.

    OK, last question… I am using Relevanssi and am wondering how to return the featured image with the result. In the relevanssi backend I can edit if I want to show snippets, author, etc etc, but I cannot find where to return the image.

    Any tips?

    #1002141

    Hi,

    Thanks for the update.

    The following thread should help you add the featured images on the search results page:

    // https://kriesi.at/support/topic/add-featured-image-to-search-results/#post-249161

    Best regards,
    Ismael

    #1003263

    Hey Ismael,

    Thanks for the link! I was actually able to figure this one out on my own (and by that I mean looking on StackOverflow haha).

    My search is working as I want it, but I have one final question… how can I get the search results to display on the same page that I have the search bar on? As it works now the results are being displayed on a new page. I am guessing I need to do something to the loop-search.php file.

    Thank you for your help!

    Here are my search.php and loop-search.php files:

    <?php
    	if ( !defined('ABSPATH') ){ die(); }
    
    	global $avia_config;
    
    	/*
    	 * get_header is a basic wordpress function, used to retrieve the header.php file in your theme directory.
    	 */
    	 get_header();
    
    	 //	allows to customize the layout
    	 do_action( 'ava_search_after_get_header' );
    
    	 $results = avia_which_archive();
    	 echo avia_title(array('title' => $results ));
    
    	 do_action( 'ava_after_main_title' );
    	 ?>
    
    		<div class='container_wrap container_wrap_first main_color <?php avia_layout_class( 'main' ); ?>'>
    
    			<div class='container'>
    
    				<main class='content template-search <?php avia_layout_class( 'content' ); ?> units' <?php avia_markup_helper(array('context' => 'content'));?>>
    
                        <div class='page-heading-container clearfix'>
                            <section class="search_form_field">
                                <?php
                                // echo "<h4>".__('New Search','avia_framework')."</h4>";
                                echo "<p>".__('Looking for something else? Try searching again','avia_framework')."</p>";
    
                                get_search_form();
                                echo "<span class='author-extra-border'></span>";
                                ?>
                            </section>
                        </div>
    
                        <?php
                        if(!empty($_GET['s']) || have_posts())
                        {
                            echo "<h4 class='extra-mini-title widgettitle'>{$results}</h4>";
    
                            /* Run the loop to output the posts.
                            * If you want to overload this in a child theme then include a file
                            * called loop-search.php and that will be used instead.
                            */
                            $more = 0;
                            get_template_part( 'includes/loop', 'search' );
    
                        }
    
                        ?>
    
    				<!--end content-->
    				</main>
    
    				<?php
    
    				//get the sidebar
    				$avia_config['currently_viewing'] = 'page';
    
    				get_sidebar();
    
    				?>
    
    			</div><!--end container-->
    
    		</div><!-- close default .container_wrap element -->
    
    <?php get_footer(); ?>
    
    <?php
    global $avia_config;
    
    // check if we got posts to display:
    if (have_posts()) :
    	$first = true;
    
    	$counterclass = "";
    	$post_loop_count = 1;
    	$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	if($page > 1) $post_loop_count = ((int) ($page - 1) * (int) get_query_var('posts_per_page')) +1;
    	$blog_style = avia_get_option('blog_style','multi-big');
    
    	while ( have_posts() ) : the_post();
    
    	$the_id 		= get_the_ID();
    	$parity			= $post_loop_count % 2 ? 'odd' : 'even';
    	$last           = count($wp_query->posts) == $post_loop_count ? " post-entry-last " : "";
    	$post_class 	= "post-entry-".$the_id." post-loop-".$post_loop_count." post-parity-".$parity.$last." ".$blog_style;
    	$post_format 	= get_post_format() ? get_post_format() : 'standard';
    
    	?>
    
    	<article <?php post_class('post-entry post-entry-type-'.$post_format . " " . $post_class . " "); avia_markup_helper(array('context' => 'entry')); ?>>
            <div class="entry-content-wrapper clearfix <?php echo $post_format; ?>-content">
    
                <header class="entry-content-header portfolio-search">
                    <?php
                    the_post_thumbnail('thumbnail');
                    // echo "<span class='search-result-counter {$counterclass}'>{$post_loop_count}</span>";
                    //echo the post title
                    $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false));
                    echo "<h2 class='post-title entry-title'><a title='".the_title_attribute('echo=0')."' href='".get_permalink()."' $markup>".get_the_title()."</a></h2>";
    
                    ?>
    
                </header>
    
                <?php
                    echo '<div class="entry-content" '.avia_markup_helper(array('context' => 'entry_content','echo'=>false)).'>';
                    $excerpt = trim(get_the_excerpt());
                    if(!empty($excerpt))
                    {
                        the_excerpt();
                    }
                    else
                    {
                        $excerpt = strip_shortcodes( get_the_content() );
                        $excerpt = apply_filters('the_excerpt', $excerpt);
                        $excerpt = str_replace(']]>', ']]>', $excerpt);
                        echo $excerpt;
                    }
                    echo '</div>';
                ?>
            </div>
    
            <footer class="entry-footer"></footer>
    
            <?php do_action('ava_after_content', $the_id, 'loop-search'); ?>
    	</article><!--end post-entry-->
    
    	<?php
    
    		$first = false;
    		$post_loop_count++;
    		if($post_loop_count >= 100) $counterclass = "nowidth";
    	endwhile;
    	else:
    
    ?>
    
    	<article class="entry entry-content-wrapper clearfix" id='search-fail'>
                <p class="entry-content" <?php avia_markup_helper(array('context' => 'entry_content')); ?>>
                    <strong><?php _e('Nothing Found', 'avia_framework'); ?></strong><br/>
                   <?php _e('Sorry, no posts matched your criteria. Please try another search', 'avia_framework'); ?>
                </p>
    
                <div class='hr_invisible'></div>
    
                <section class="search_not_found">
                    <p><?php _e('You might want to consider some of our suggestions to get better results:', 'avia_framework'); ?></p>
                    <ul>
                        <li><?php _e('Check your spelling.', 'avia_framework'); ?></li>
                        <li><?php _e('Try a similar keyword, for example: tablet instead of laptop.', 'avia_framework'); ?></li>
                        <li><?php _e('Try using more than one keyword.', 'avia_framework'); ?></li>
                    </ul>
    
                    <div class='hr_invisible'></div>
                    <h3 class=''><?php _e('Feel like browsing some posts instead?', 'avia_framework'); ?></h3>
    
            <?php
            the_widget('avia_combo_widget', 'error404widget', array('widget_id'=>'arbitrary-instance-'.$id,
                    'before_widget' => '<div class="widget avia_combo_widget">',
                    'after_widget' => '</div>',
                    'before_title' => '<h3 class="widgettitle">',
                    'after_title' => '</h3>'
                ));
            echo '</section>';
    	echo "</article>";
    
    	endif;
    	echo avia_pagination('', 'nav');
    ?>
    

    Thanks!

    #1003444

    Hi,

    Nice. Unfortunately, what you’re asking requires modifications that are beyond the scope of support. You will have to call an AJAX request to render the search results on the page where the search bar is located. A simple workaround is to just put the same search bar on the search results page.

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.