Search Results for 'current_query'

Forums › Forums › Search › Search Results for 'current_query'

Viewing 10 results – 191 through 200 (of 385 total)
  • Author
    Search Results
  • #185435

    In reply to: Showing search results


    Trevor
    Participant

    The text that starts:

    Architecten, interieurdesigners, vormgevers …

    What about the title? and the breadcrumbs?

    And you want to stay on that page? This means the display of the text needs to be conditional, and that means that you would need to output the text conditionally using PHP (the PHP needs to detect if a search has been made). The safest way to do this is to create the PHP as a shortcode and place the shortcode in to a Visual Composer (Page Builder) Text element.

    This plugin allows you to create a shortcode with PHP in it:

    https://wordpress.org/plugins/php-code-widget/

    The PHP would look something like:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(187)->current_query();
    if ((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()=="")) {
      echo '<div>Nothing to see here folks!</div>'; 
    } else {
      // your page title, breadcrumbs, text here
    }

    That is the theory of it.

    #184592

    Trevor
    Participant

    If you are using the Shortcode results method, and our results.php template file, 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).

    #182014

    Trevor
    Participant

    You would need to be using our Shortcode Display results method, and have followed the guide to customising:

    https://support.searchandfilter.com/documentation/search-filter-pro/search-results/using-a-shortcode/

    Once you have a copy of the results.php file in a search-filter sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):

    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 {
      // the results.php PHP code here
    }

    Make sure you change the ID number in that snippet to the ID number of your form.

    #181946

    Trevor
    Participant

    The Custom method relies on a theme template of some sort. Are you using a theme php template, as the logic would look something like this to do as you want:

    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 {
      // the theme template PHP code here
    }

    Change the number 1024 with your form’s ID number (from the shortcode).

    This code will likely need to be used within a part the template file that actually outputs the results (around the if query … have … posts bit).

    #181171

    Trevor
    Participant

    You could use PHP to look at the array that holds the filter arguments, and conditionally load different code in the same template. Again, that is custom coding.

    To start with, put this code on the results page in a suitable place:

    $sf_current_query_array = $searchandfilter->get(1446)->current_query()->get_array();
    echo '<pre>';
    print_r($sf_current_query_array);
    echo '</pre>';

    CHANGE THE ID NUMBER in the above code (1446) to whatever the ID of you form is.

    You will then see the array of filters used, and you can figure than how to fetch the value you need to add PHP to your template to test what the user has selected.

    #180524

    Trevor
    Participant

    Ah, that will be easier to do in V3 of our plugin, but for now it would have to be custom coded. This documentation page is a starting point:

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

    Many users have posted more complex solutions, and this search should pick up some of those threads:

    https://support.searchandfilter.com/forums/search/current_query%28%29+get_array%28%29/


    Anonymous
    Inactive

    How can I set up a custom message when search returns 0 results?

    Site: Click here

    My code:

    <?php
    
    global $searchandfilter;
    
    $atrair_home = $searchandfilter->get(180)->current_query();
    
        if ((!$atrair_home->is_filtered())&&($atrair_home->get_search_term()=="")) {
    
            $args = array(
                'post_type' => array(
                    'post',
                    'ebooks',
                    'podcasts',
                    'videos'
                ),
                'post_status' => 'publish',
               );
               
              $posts = new WP_Query( $args );
              if( $posts->have_posts() ) :
              ?>
        <?php
                    while( $posts->have_posts() ) :
                      $posts->the_post();
                      ?>
            <div class="posts-double">
    				<?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
    				<a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark">
    					<?php 
    										$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
    										echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?>
    					<?php endif; ?>
    				</a>
    				<div class="content">
    					<a class="title" href="<?php the_permalink() ?>" rel="bookmark">
    						<?php the_title(); ?>
    					</a>
    					<p class="descriptions">
    						<?php echo wp_trim_words( get_the_content(), 15, '...' );?>
    					</p>
    					<div class="related-post-category">
    						<?php the_tags(); 
    								$post_type = get_post_type(get_the_ID());
    								$post_name = get_post_type_object(get_post_type())->labels;
    								if ( $post_type != 'post' ) {
    									echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>';
    								};
    								?>
    					</div>
    				</div>
    				<div class="posts-footer">
    						<div class="related-time">
    							<?php echo do_shortcode('[rt_reading_time]'); ?>
    						</div>
    						<div class="related-bookmark">
    							<?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?>
    						</div>
    					</div>
    			</div>
            <?php
                    endwhile;
                    wp_reset_postdata();
        
              else :
                echo 'Não conseguimos encontrar nenhum resultado...';
              endif;
        
                }
    
        else
        //Inicio fim
        {
    
            if ( $query->have_posts() )
            {
                ?>
                
                Found <?php echo $query->found_posts; ?> Results<br />
                <div class='search-filter-results-list'>
                <?php
                    while ($query->have_posts())
                    {
                        $query->the_post();
                        
                        ?>
                                <div class="posts-double">
                            <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
                            <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark">
                                <?php 
                                                    $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
                                                    echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?>
                                <?php endif; ?>
                            </a>
                            <div class="content">
                                <a class="title" href="<?php the_permalink() ?>" rel="bookmark">
                                    <?php the_title(); ?>
                                </a>
                                <p class="descriptions">
                                    <?php echo wp_trim_words( get_the_content(), 15, '...' );?>
                                </p>
                                <div class="related-post-category">
                                    <?php the_tags(); 
                                            $post_type = get_post_type(get_the_ID());
                                            $post_name = get_post_type_object(get_post_type())->labels;
                                            if ( $post_type != 'post' ) {
                                                echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>';
                                            };
                                            ?>
                                </div>
                            </div>
                            <div class="posts-footer">
                                    <div class="related-time">
                                        <?php echo do_shortcode('[rt_reading_time]'); ?>
                                    </div>
                                    <div class="related-bookmark">
                                        <?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?>
                                    </div>
                                </div>
                        </div>
                
                                <?php
                                
                
                    }
                ?>
                </div>
            <?php
            }
            else
            {
                ?>
                <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
                    <span>End of Results</span>
                </div>
                <?php
            }
        }
            ?>
    #180060

    In reply to: Search results for ""


    Anonymous
    Inactive

    Hi Trevor,

    Thanks for your help with this. It looks like the code I need to use is:

    Get the Search Term
    <?php
    //Get the search term
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    echo $sf_current_query->get_search_term();
    ?>

    However, I’m not clear where I should be inserting this in the theme – should I be looking for the search.php template file and inserting it in there where the searched terms are shown?

    Thanks,

    Matthew

    #179684

    Anonymous
    Inactive

    Hello!

    I’m using search and filter pro v2.4.3 with Relevanssi.

    This code displays the results on each custom search.

    <?php
    
    global $searchandfilter;
    
    $analisar_home = $searchandfilter->get(312)->current_query();
    
        if ((!$analisar_home->is_filtered())&&($analisar_home->get_search_term()=="")) {
    
            $args = array(
                'post_type' => array(
                    'post',
                    'ebooks',
                    'podcasts',
                    'videos'
                ),
                'cat' => 5,
                'posts_per_page' => 5,
                'post_status' => 'publish',
                'orderby' => 'date',
                'posts_per_page' => -1,
               );
               
              $posts = new WP_Query( $args );
              if( $posts->have_posts() ) :
              ?>
        <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( $posts->have_posts() ) :
                      $posts->the_post();
                      ?>
            <div class="search-box">
                <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
                <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark">
                    <?php 
                                        $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
                                        echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?>
                    <?php endif; ?>
                </a>
                <div class="content">
                    <a class="title" href="<?php the_permalink() ?>" rel="bookmark">
                        <?php the_title(); ?>
                    </a>
                    <p class="descriptions">
                        <?php echo wp_trim_words( get_the_content(), 25, '...' );?>
                    </p>
                    <div class="related-post-category">
                        <?php the_tags(); 
                                $post_type = get_post_type(get_the_ID());
                                $post_name = get_post_type_object(get_post_type())->labels;
                                if ( $post_type != 'post' ) {
                                    echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>';
                                };
        
                                $terms = get_the_category( $post->ID ); //Get all the terms
                                
                                foreach ($terms as $term) { //Cycle through terms, one at a time
                                
                                // Check and see if the term is a top-level parent. If so, display it.
                                $parent = $term->parent;
                                if ( $parent=='0' ) {
                                
                                    $term_id = $term->term_id; //Define the term ID
                                    $term_link = get_term_link( $term); //Get the link to the archive page for that term
                                    $term_name = $term->name;
                                    $term_slug = $term->slug;
                                    echo '<a class="' . $term_slug . '" href="' . $term_link . '"><span class="label">' . $term_name . '</span></a>';	
                                } }
                                ?>
                    </div>
                    <div class="related-post-footer">
                        <div class="related-time">
                            <?php echo do_shortcode('[rt_reading_time]'); ?>
                        </div>
                        <div class="related-bookmark">
                            <?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php
                    endwhile;
                    wp_reset_postdata();
        
              else :
                esc_html_e( 'Não conseguimos encontrar nenhum resultado...', 'text-domain' );
              endif;
        
                }
    
        else 
        //Inicio fim
        {
    	?>
    
                <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 class="search-box">
                        <?php if ( has_post_thumbnail()) : // Check if Thumbnail exists ?>
                        <a class="thumbnail" href="<?php the_permalink() ?>" rel="bookmark">
                            <?php 
                                    $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
                                    echo '<div class="image" style="background:url('.esc_url($featured_img_url).')"></div>' ?>
                            <?php endif; ?>
                        </a>
                        <div class="content">
                            <a class="title" href="<?php the_permalink() ?>" rel="bookmark">
                                <?php the_title(); ?>
                            </a>
                            <p class="descriptions">
                                <?php echo wp_trim_words( get_the_content(), 25, '...' );?>
                            </p>
                            <div class="related-post-category">
                                <?php the_tags(); 
                                    $post_type = get_post_type(get_the_ID());
                                    $post_name = get_post_type_object(get_post_type())->labels;
                                    if ( $post_type != 'post' ) {
                                        echo '<a href="'.get_post_type_archive_link( $post_type ).'"><span class="'.$post_type.'">'.$post_name->name.'</span></a>';
                                    };
    
                                    $terms = get_the_category( $post->ID ); //Get all the terms
                                    
                                    foreach ($terms as $term) { //Cycle through terms, one at a time
                                    
                                    // Check and see if the term is a top-level parent. If so, display it.
                                    $parent = $term->parent;
                                    if ( $parent=='0' ) {
                                    
                                        $term_id = $term->term_id; //Define the term ID
                                        $term_link = get_term_link( $term); //Get the link to the archive page for that term
                                        $term_name = $term->name;
                                        $term_slug = $term->slug;
                                        echo '<a class="' . $term_slug . '" href="' . $term_link . '"><span class="label">' . $term_name . '</span></a>';	
                                    } }
                                    ?>
                            </div>
                            <div class="related-post-footer">
                                <div class="related-time">
                                    <?php echo do_shortcode('[rt_reading_time]'); ?>
                                </div>
                                <div class="related-bookmark">
                                    <?php echo do_shortcode('[cbxwpbookmarkbtn]'); ?>
                                </div>
                            </div>
                        </div>
                    </div>
    
                    <?php
    	}
    	?>
    
                    <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
    }
    ?>

    This code lists posts without any search. The problem is, when I use any filter on the search, the results dont show custom posts types, only regular posts.

    Here you can see that my configs are right.

    Please, can you help me? I’m trying to figure out at least 4 days what is going on…

    Thanks

    #179658

    Trevor
    Participant

    You would need to be using our Shortcode Display results method, and have followed the guide to customising:

    https://support.searchandfilter.com/documentation/search-filter-pro/search-results/using-a-shortcode/

    Once you have a copy of the results.php file in a search-filter sub-folder of your theme, you can edit that file, like this (leave the PHP comments at the top outside and before this code):

    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 {
      // the results.php PHP code here
    }

    Make sure you change the ID number in that snippet to the ID number of your form.

Viewing 10 results – 191 through 200 (of 385 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.