Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 151 through 160 (of 344 total)
  • Author
    Search Results
  • #195882

    Anonymous
    Inactive

    Hey,

    I’m using PHP, so if this is the query:

    $sf_current_query = $searchandfilter->get(1033)->current_query();

    Once I have $sf_current_query how do I feed that into wp_query to return a specific set of results?

    Thanks,
    Dan

    #193405

    Trevor
    Participant

    Yes, like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12204)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your template archive code/loop OR results.php code here
    }
    #192425

    Anonymous
    Inactive

    Thanks for the links about this subject and great to hear about this option coming to the plugin in 2019.

    In this guide: https://searchandfilter.com/documentation/accessing-search-data/
    I have to use a code and replace it with the form-id. But I have 9 different forms, using the same page-template, who are switched on and off by some widget logic.
    Is their a possibility to use this code and let the code search for the right for id who is active on the page the user is visiting?:

    <?php
    	//Get a single fields values using labels
    	//replace <code>1526</code> with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1526)->current_query();
    	echo $sf_current_query->get_field_string("_sft_category");
    	
    ?>
    #192423

    Trevor
    Participant
    #192218

    In reply to: Search results


    Trevor
    Participant

    Ah, I can see what you have done now. It would need for part of the blog page template to be placed in the results.php file and for the blog template instead of calling the results shortcode, to call the content.

    I can write this for you if you want:

    In blog-page.php change lines 24-29:

    <div class="page-blog page-blog-title">Recent posts</div>
      <div class="blog-posts">
    
        <?php echo do_shortcode('[searchandfilter id="463" show="results"]');?>
      </div>
    </div>

    with:

    <?php the_content(); ?>
    

    Next, in the results.php file, find lines 68 and 69:

    </a></a>
    </div>

    I believe these have errors and should be just:

    </a>
    

    At the very end of the file is a blank line, after this:

    else  ?>
    
    <?php {
    	
    }
    ?>

    Here add two closing tags:

    </div>
    </div>

    Now find lines 25 and 26 (which are blank) and paste these lines:

    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(463)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      $page_title = "Recent Posts"; 
    } else {
      $page_title = "Search results for: " . $sf_current_query->get_search_term();
    }?>
    <div class="page-blog page-blog-title">Recent posts</div>
      <div class="blog-posts">

    I think that will do as you want. The title must be inside the results.php for it to be affected by if there are results.

    #192127

    In reply to: Search results


    Trevor
    Participant

    The text that says Recent post is what that line I highlighted makes. In any event that lines needs to be this instead, I think (try it):

    <div class="blog-post__title"><?php the_title();?></div>

    So, you would now need to find out if the page is filtered, like this, where the last line replaces line 42:

    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      $page_title = the_title(); 
    } else {
      $page_title = "Search results for: " . $sf_current_query->get_search_term();
    }?>
    <div class="blog-post__title"><?php echo $page_title;?></div>

    Note that this only shows the text search term. If you want fields choices, taxonomy choices, it becomes more complicated, which is what that documentation page shows how to do..

    #191996

    Trevor
    Participant

    As you are using the WooCommerce method to display results, it is your theme and/or WooCommerce that controls the output of the HTML and results. If you have access to the PHP template file being used, this PHP will generally detect if a search has been made or not:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(20549)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      // your template archive code to show when there is search yet
    } else {
      // your template archive code to show search results
    }
    #191321

    Trevor
    Participant

    As you are using the Shortcode results method, and our results.php template file (infinite scroll version), it would look like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1024)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your template archive code/loop OR results.php code here
    }

    Change 1024 to the ID number of your form (from the form shortcode).

    #191069

    Trevor
    Participant

    Do you have this bit:

    echo $sf_current_query->get_search_term();

    #191067

    Anonymous
    Inactive

    I don’t have any other filters, and the first link/example doesn’t seem to work.

    <?php
    //grab the active query from our search form
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1445)->current_query();
    ?>

    This should grab the search term and output it on the page, right?

Viewing 10 results - 151 through 160 (of 344 total)