Forums Forums Search & Filter Pro How Restrict Search & Filter Widget

Viewing 8 posts - 1 through 8 (of 8 total)
  • Anonymous
    #1802

    Hi,

    When reading this forum I noticed that Search & Filter does not work when any of “restrict widget” plugins are enabled. I tried some of them (Widget Logic, Widget Logic By Path, Display Widget, Restrict Widget, Widgets Controller, Widget Context), but with none of them AJAX search seems to work.

    Is there any way how to restrict Search & Filter widget to specific page AND to use AJAX search?

    Also do you have any suggestions what custom search template should I use (or create) to display search results in the same way as on your Woocommerce demo site? I am using Divi theme.

    Thanks!
    Petr

    Ross Moderator
    #1807

    Hey Petr

    Yes, basically you need to create your own template, and create a widget area specifically for this page…

    1) Make sure custom template is ticked in admin
    2) Make sure you enter a slug (ie product-search)
    3) Create your custom template

    Now that you are using a slug you can access your search results like:
    yoursite.com/product-search and if you are using a custom template then you can restrict S&F to only appear on this template.

    Now the tricky part…. I had to do quite a lot of modification to get it working with the mystile theme exactly how I wanted.

    First I duplicated the archive-product.php from the woocommerce templates folder and called this products-search.php and put this in my theme folder.

    Then I create and register a sidebar, so…. Add this code to functions.php of your theme:

    register_sidebar(array(
    	'name'=> 'Search & Filter Form Widgets',
    	'id' => 'search_filter_form_widget',
    	'before_widget' => '',
    	'after_widget'  => '',
    	'before_title'  => '<h2 class="widgettitle">',
    	'after_title'   => '</h2>'
    ));

    Now you will find a new widget area to add S&F widget.

    We need to include this in our products-search.php though so we must create a sidebar first…

    Create a new file in your theme folder called sidebar-search-form.php and add the code:

    <?php 
    /**
     * Sidebar Template
     *
     * If a <code>primary</code> widget area is active and has widgets, display the sidebar.
     *
     * @package WooFramework
     * @subpackage Template
     */
    	global $woo_options;
    	
    	if ( isset( $woo_options['woo_layout'] ) && ( $woo_options['woo_layout'] != 'layout-full' ) ) {
    ?>	
    <aside id="sidebar" class="col-right">
    
    	<?php dynamic_sidebar( 'search_filter_form_widget' ); ?>
    	
    </aside><!-- /#sidebar -->
    <?php } // End IF Statement ?>

    Now we have a sidebar that loads our custom widget area…. but this is still not in our template… so in the template product-search.php add:

    <?php 
    	get_sidebar('search-form');
    ?>

    And there you have it! A new widget area just for your custom template 🙂

    Anonymous
    #1833

    Hi Ross,

    Thanks a lot for narrowing this down. The only issue I have is that when the sidebar is generated using the template, it generates the default sidebar, not the custom one.

    It seems that the file sidebar-search-form.php is for some reason not processed.

    Also when I use this code:
    <?php get_sidebar('search-form'); ?>
    it does not generate anything.

    When I switch it to:
    <?php get_sidebar('sidebar-search-form'); ?>

    It generates the sidebar, but only the default one.

    Petr

    Anonymous
    #1855

    Hi Ross,

    I got it somehow working, so I wanted to thank you for your help!

    Petr

    Ross Moderator
    #1856

    Hey Petr no worries glad its working ok now 🙂

    Ross Moderator
    #1857
    This reply has been marked as private.
    Anonymous
    #19780

    I’ve followed these instructions, but the sidebar search widget appears in the footer on search result pages. If I move the location of the following:

    <?php get_sidebar(‘sidebar-search-form’); ?>

    I can get the sidebar widget to move to the header and body, but never over to the right hand side of the page. Any idea what I’m doing wrong?

    Ross Moderator
    #19798

    Hey Scott, can you open a new ticket?

    Thanks

Viewing 8 posts - 1 through 8 (of 8 total)