Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 111 through 120 (of 344 total)
  • Author
    Search Results
  • #220031

    Trevor
    Participant

    From your original code I would have had this:

    <?php
    /**
     * Search & Filter Pro 
     *
     * Sample Results Template
     * 
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      http://www.designsandcode.com/
     * @copyright 2015 Designs & Code
     * 
     * Note: these templates are not full page templates, rather 
     * just an encaspulation of the your results loop which should
     * be inserted in to other pages by using a shortcode - think 
     * of it as a template part
     * 
     * This template is an absolute base example showing you what
     * you can do, for more customisation see the WordPress docs 
     * and using template tags - 
     * 
     * http://codex.wordpress.org/Template_Tags
     *
     */
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(233)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
    if ( $query->have_posts() )
    {
    	?>
          
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    	
    	    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		    <a href="<?php the_permalink(); ?>" alt="<?php the_title(); ?>">
    		        <h2><?php the_title(); ?></h2>
                    <?php if( get_field('summary_portfolio_description') ): ?>
                        <p><?php the_field('summary_portfolio_description'); ?></p> 
                    <?php endif; ?>		        
    		       <?php the_excerpt(); ?>
                </a>
            </article>
            
    		<?php
    	}
    
    }
    else
    {
    	echo "<span id='no-results'>No results found, please try altering your search criteria.</span>";
    }
    }
    ?>
    #219973

    Anonymous
    Inactive

    Hi Trevor,

    Thanks for the prompt reply, I’ve amended my results.php file as per your suggestion on that other post but I think I’ve done something wrong as no results show now.

    This is my code:

    if ( $query->have_posts() )
    {
    	?>
          
    	<?php
    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(233)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
         
            
    		?>
    	
    	  Results code here.
            
    		<?php} 
    	}
    
    ?>

    Any ideas where I’m going wrong with this?

    Thanks,

    James

    #219094

    Trevor
    Participant

    That plugin, and others like it, will impact sorting in our plugin as it acts later in the WordPress page creation process. Post Types Order does have a hook you can use though, to stop it working under conditions that you set. It is discussed here:

    https://wordpress.org/support/topic/to-avoid-plugin-conflict-how-to-disable-post-type-order-for-search-pages/

    Maybe like this (in your child theme functions.php file):

    add_filter('pto/posts_orderby/ignore', 'pto_ignore', 10, 3);
    function pto_ignore( $ignore, $orderBy, $query ) {
      global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
    } else {
      $ignore = TRUE;
    }
    return $ignore; 
    }

    Where 12345 is changed to the ID of your search?

    I am not sure if this is much the same, but simpler/shorter:

    add_filter('pto/posts_orderby/ignore', 'pto_ignore', 10, 3);
    function pto_ignore( $ignore, $orderBy, $query ) {
      global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query();
    if (!((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==""))) $ignore = TRUE;
    return $ignore; 
    }
    #216800

    Anonymous
    Inactive

    Thank you for your support.

    I would like put add more information about current situation.
    1.Form 78 and Form 50 have different search form UI.

    Form 50 -> line
    Form 78 -> price, some preference etc..

    Could you please provide some solution ?

    2.what is the Active Query Object for ? where do I need to put this code ?

    <?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(1526)->current_query();
    ?>

    https://searchandfilter.com/documentation/accessing-search-data/

    Regards,

    #215861

    Anonymous
    Inactive

    I get the array on the result page using this code:
    <?php
    //Get the search term
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(154)->current_query();
    echo $sf_current_query->get_fields_html(
    array(“_sft_manufacturer”, “_sft_year”,”_sft_engine_type”,”_sft_engine_model”)
    );
    ?>
    it shows:
    manufacturers: crusader
    years: All years
    engine type: inboard
    Engine Model: All Engine Model

    So how to let it show on woocommerce new order email ?

    Thanks.


    Trevor
    Participant

    The ‘As an Archive’ method might cause that to happen

    add_action('pre_get_posts', 'myprefix_query_offset', 1 );
    function myprefix_query_offset(&$query) {
      if (is_front_page() && $query->is_main_query()){
        global $searchandfilter;
        $sf_current_query = $searchandfilter->get(12345)->current_query();
        if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
          return;
        } else {
    // RUN CODE ONLY ON FRONT PAGE AND MAIN QUERY
        }
      }
    }

    That might work. Change 12345 for the ID of your form.


    Trevor
    Participant

    To fetch the search terms, the https://searchandfilter.com/documentation/accessing-search-data/ guide is basic but you can extend the idea to grab lots of other data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    You could use this to display the filter array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where the ID needs to match that of your form.

    #215288

    Trevor
    Participant

    I am not sure if this is what you want. To show the filters, as I said, this requires custom coding when using the current version of Search & Filter Pro. You can access the filter terms though, but would need further PHP work to display them. To fetch the search terms, the

    https://searchandfilter.com/documentation/accessing-search-data/

    guide is basic but you can extend the idea to fetch other filter terms/data. If you have other filters, then it becomes a little more complex, but I can give you links. This thread might help you:

    https://support.searchandfilter.com/forums/topic/accessing-field-slug-on-search-results/

    … and this search will give similar threads I think:

    https://support.searchandfilter.com/forums/search/sf_current_query+get_array+field+%5Bvalue%5D/

    Note, if you are using Ajax refreshing of the results, any PHP needs to be inside the Ajax Container, or it will not update.

    #213402

    Anonymous
    Inactive

    i use the shortcode to display my result, and in the shortcode I use the next code

    $sf_current_query = $searchandfilter->get( 1391 )->current_query();
    the get( 1391 ) is fixed ID….

    i need something like
    $sf_current_query = $searchandfilter->get( $sfid )->current_query();

    #213328

    Trevor
    Participant

    You can find more details from the filter query array.

    You may need to temporarily output the array to see how to access the term that you want.

    If you add this code to the page, it will output the entire array:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1391)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>
Viewing 10 results - 111 through 120 (of 344 total)