Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 291 through 300 (of 344 total)
  • Author
    Search Results

  • Trevor
    Participant

    Something like 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(1726)->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() )
    {
    	?>
    	
    	Found <?php echo $query->found_posts; ?> Results<br />
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    	
    	<div class="pagination">
    		
    		<div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
    		<?php
    			/* example code for using the wp_pagenavi plugin */
    			if (function_exists('wp_pagenavi'))
    			{
    				echo "<br />";
    				wp_pagenavi( array( 'query' => $query ) );
    			}
    		?>
    	</div>
    	
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    		<div>
    			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    			
    			<p><br /><?php the_excerpt(); ?></p>
    			<?php 
    				if ( has_post_thumbnail() ) {
    					echo '<p>';
    					the_post_thumbnail("small");
    					echo '</p>';
    				}
    			?>
    			<p><?php the_category(); ?></p>
    			<p><?php the_tags(); ?></p>
    			<p><small><?php the_date(); ?></small></p>
    			
    		</div>
    		
    		<hr />
    		<?php
    	}
    	?>
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    	
    	<div class="pagination">
    		
    		<div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
    		<?php
    			/* example code for using the wp_pagenavi plugin */
    			if (function_exists('wp_pagenavi'))
    			{
    				echo "<br />";
    				wp_pagenavi( array( 'query' => $query ) );
    			}
    		?>
    	</div>
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }
    }
    ?>

    I think?

    #67748

    Anonymous
    Inactive

    On your documentation

    https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    you say this is possible querying the form from another page:

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

    Whould this display the filtered posts to a php template?


    Trevor
    Participant

    Hi

    For 1 and 2, you would need to edit the results.php file that you copied into your theme folder. 3 is not possible, yet. It is on our roadmap, but it may be a while yet, to allow form elements in different places on the page.

    So, for 1. This is the basic code:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    if (!$sf_current_query->is_filtered()) {
    // put anything you want instead of the results for the page loading without query parameter
    } else {
    // put the output part of the results.php here
    }

    Where 1726 is changed to whatever the ID number of your form is.

    For 2, simply find those text strings in the results.php file and replace.

    #64663

    Anonymous
    Inactive

    Is this also work in sf_input_object_pre that you gave me?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();

    #64374

    Trevor
    Participant

    Hi

    It all seems to work for me?

    As to not showing results when the page loads, you need to edit the results.php file, like this:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    if (!$sf_current_query->is_filtered()) {
    // put anything you want instead of the results for the page loading without query parameter
    } else {
    // put the output part of the results.php here
    }
    #59296

    In reply to: Access active query


    Anonymous
    Inactive

    Exactly, I wanto to check if query is filtered and then display something that doesn’t inovolve posts. It’s a custom code. I tried $searchandfilter->get(filter_id)->current_query() with is_filtered() but it always returns 1.

    #58751

    In reply to: default value


    Trevor
    Participant

    Nor am I 🙁 I have done some, but not a lot. My guess, for you, you would need something more like:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    if (!$sf_current_query->is_filtered()) {
    // put your javascript here
    }
    #58717

    In reply to: default value


    Anonymous
    Inactive

    Hi,
    Thanks ,

    I’m not a developer with JavaScript, but I’ll try.
    I have to test with.:
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    if ($sf_current_query->is_filtered()) {
    // do the loop
    } else {
    // initialize data with javascript
    }
    where do I insert the javascript?
    for exemple to set a date with the today’s date (_sfm_my_date)
    Thanks

    #57149

    Anonymous
    Inactive

    Actually I spoke to soon.

    The if statement in this thread doesn’t quite work. It partly works insofar as there are no results on initial page load, and if I choose a category or tag then results appear. So far so good. But if I just search for word there are no results at all.

    If I remove the if statement then I do get results.

    Is if ($sf_current_query->is_filtered()) supposed to trigger if a word has been searched for?

    #56017

    Trevor
    Participant

    In PHP you need to take the string and modify it. The first thing is to remove the Location: string. So, you use the PHP Search function to find the :, like this:

    $return_string = $sf_current_query->get_fields_html(array("_sft_locatie");
    $colon_pos = strpos($return_string, ":");

    Then you fetch the right most part of the return_string after the colon:

    $return_string_trim = substr($return_string, $colon_pos+1);
    

    Then you replace the commas with <br />:

    $return_string_html = str_replace(",", "<br />", $return_string_trim);
    

    And then you return the string:

    return $return_string_html;
    

    At least, I think ….

Viewing 10 results - 291 through 300 (of 344 total)