• Hello, great plugin. It works very well. There is one thing that I am having difficulty with though. I have the ajax search results activated and working well, however, I created a search form with a bunch of check boxes. If I check a box the results are automatically displayed where I want them. BUT… If i deselect the check box, leaving no check boxes selected, every post that I have shows up. Is there a way to prevent this from happening and either display a message like “You don’t have anything selected” or maybe go back to the content that was originally in the div that the SERP is displayed in?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TC.K

    (@wp_dummy)

    The plugin is designed in this way, it simply filter the posts, not exactly search the posts.
    But if you don’t want to display result when no checkboxes is selected then there is little tweak.

    Since you not telling the checkboxes are from taxonomy or meta fields or both, you will need to choose the one you need in the following scripts.

    Taxonomy filter:

    add_filter(' uwpqsf_get_taxo', 'add_exlude_taxo_empty','',3);
    function add_exlude_taxo_empty($taxo,$id, $gettaxo ){
         $i = 0;
         foreach($gettaxo as  $v){
              if( is_array($v['term']) && empty($v['term'])){
                   $taxo[i] = array();
              }
           $i++;
         }
        return $taxo;
    }

    Meta field filter:

    add_filter('uwpqsf_get_cmf', 'add_exlude_cmf_empty','',3);
    function add_exlude_cmf_empty($cmf,$id, $getcmf ){
      
       foreach($getcmf as  $v){
    		if(empty($v['value'])){
    			$cmf[i] = array();
    		 }
            $i++;
           }
    	  return $cmf;
    }

    Note the scripts is not tested. It might got typo or other mistake.
    If everything is correct but still not works, you need to give me your url so that I can figure other solution.

    Thread Starter ram1823

    (@ram1823)

    Yes they are all taxonomies. I added thee taxonomy script to my functions.php file but no luck.

    Here is a dev link to my site

    https://npproductdb.wp.accessamg.com/

    I really appreciate the help and quick response. Thank you.

    Plugin Author TC.K

    (@wp_dummy)

    We will using the js way then.

    function restrict_send_query() {
        ?>
        <script>
    
    jQuery(function($) {
     var formid = '#uwpqsffrom_36';change the 36 with your form id
    
     $(formid).find('input, textarea, button, select').unbind('change');//disable the default event
     
     $(formid).find('input, textarea, button, select').change(function(){ 
    	     var gotChecked = false;
    		$("#uwpqsffrom_36").find("input[type=checkbox]").each(function () {
    			//only check for checkbox input for your condition
    			if($(this).is(':checked') ){
    				gotChecked = true;
    				return false;
    			}
    	
    		});
    		if(gotChecked){
    			process_data($(this)); //proceed to the search function
    		}else{
    			alert("Please choose an option"); //you can send an alert here or simply do nothing as it will not trigger the search function
    		};
    	
    		
     });
      
     });
    	</script>
    
       <?php
    }
    add_action( 'wp_footer', 'restrict_send_query' );

    Not tested though, but the idea is here. If you know js, you can manipulate the script above. The idea is simply, disable the default change event, and create a new change event with checking the checkboxes is checked before sending the search function.

    Thread Starter ram1823

    (@ram1823)

    Hey thank you very much this works, sorry it’s been awhile I haven’t been back to work on this project in a while, and I never got an email that there was a reply.

    The only other thing I am seeing, is that now whenever I do click on a check box, a split second before the results show up, I get a “there is error here” message that pops up real quick. Is there any way I can remove that message?

    Thread Starter ram1823

    (@ram1823)

    Nevermind, I had that script in my header.php file, when i moved it to the footer that error went away.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Ajax search results displays all, when nothing is selected’ is closed to new replies.