Support Forums

Looking for support? You can access the support system via your account.

Forums Forums Search Search Results for 'found_posts'

Viewing 10 results - 21 through 30 (of 254 total)
  • Author
    Search Results
  • #259571

    giveuptheghost
    Participant

    Literally figured this out directly after posting this. I’ll post my solution for anyone interested.

    Here is the code I used in a PHP block to display the search term and a post count:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(678)->current_query();
    echo $sf_current_query->get_search_term();
    	
    $the_query = new WP_Query(array(
      'post_type' => 'courses',
    ));
    	
    echo $the_query->found_posts;
    wp_reset_postdata();

    Both before this code block and before the repeater that follows I put this shortcode (so twice):
    [searchandfilter id=”YOURSEARCHID” action=”filter_next_query”]

    I had tried this almost exactly last night (except without any arguments for $the_query) but it didn’t work. The trick was that I had to filter “$the_query” by at least one argument, in this case post_type. If I left the arguments empty or passed an empty $args, the searchandfilter shortcode wouldn’t filter. I’m assuming that shortcode is just a pre_get_posts based on the filter parameters and there needs to be at least one parameter for pre_get_posts to work.

    Either way, I believe I have it figured out – thanks for making a great plugin! It would be great to get more direct Oxygen Builder support in the future as it’s an amazing builder for people who can code but in the meantime, things are working so I’m happy!

    #259569

    giveuptheghost
    Participant

    Hi there,

    I just purchased the pro version and was able to get nearly everything to work properly with Oxygen Builder using the guide posted by Jan Langhans here:

    https://support.searchandfilter.com/forums/topic/search-and-filter-pro-oxygen-builder-repeater/

    I was even able to make it work with an Oxygen Archive template even though that post said it wasn’t possible (although I still have to enter the page url for where the template will appear).

    Additionally, I was able to display the current search result by using a PHP block and using this code:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(678)->current_query();
    echo $sf_current_query->get_search_term();

    I wrote out everything I can do just to show why it is so frustrating that I can’t figure out how to simply display the total results count after being filtered by Search and Filter Pro. I tried echo $sf_current_query->found_posts; directly after the code I have above and that comes back as null and displays nothing. I tried creating a new wp query and using found_posts with that but that just displays the total count unfiltered by search and filter. I have a feeling there’s some simple way to access the total results like the get_search_term() function above but I just can’t figure it out.

    Any help would be greatly appreciated!

    #257846

    Trevor
    Moderator

    If you are using the Shortcode display results method …

    If you haven’t already done so, can you follow this guide:

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

    In particular, follow the instructions in the Customising section.

    However, I think you have missed this crucial step, based on your post:

    Rather than copy the results.php file to your theme sub-folder, copy the results-infinite-scroll.php file, and then rename it to results.php

    The code for this file is different, to account for how the Infinite Scroll works.

    That will give you a results.php file you can edit, in a sub-folder named search-filter in your theme folder.

    So, look for this code in the results.php template file:

    Found <?php echo $query->found_posts; ?> Results<br />

    … and delete that line.

    Please note that in the UK today is a public holiday, so further replies may be delayed.

    #256885

    In reply to: No search results


    Trevor
    Moderator

    I apologise for the delay Jens, I ran out of time yesterday.

    If you haven’t already done so, can you follow this guide:

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

    In particular, follow the instructions in the Customising section.

    That will give you a results.php file you can edit, in a sub-folder named search-filter in your theme folder.

    Would you want to show that after you search? My guess is yes. So, look for this code in the results.php template file:

    Found <?php echo $query->found_posts; ?> Results<br />
    Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />

    And change that to (I think this will work):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(30408)->current_query();
    if (!((!$sf_current_query->is_filtered())&&($sf_current_query->get_search_term()==""))) {
    	Found <?php echo $query->found_posts; ?> Results<br />
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    }

    You can change anything else you want also. For example, to make the pagination look nicer, install the free WP-PageNavi plugin and delete these lines:

    <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>
    
    #254877

    In reply to: Count for All Items


    Trevor
    Moderator

    All it will do is count the counts from other options, which it is doing. If there are posts without options, that it cannot do. For that you would need to find the total posts count and add that to the label.

    The input object does not have that count, but the results array does, generally fetched, I think, like this:

    $total_count = $query->found_posts;

    #254727

    In reply to: Results count


    Christian Thibault
    Participant

    Trevor,

    It works.
    $sf_current_query = $searchandfilter->get($id)->current_query();
    $term = $sf_current_query->get_search_term();
    $count = $wp_query->found_posts;

    Thank you,

    Christian

    #254714

    In reply to: Results count


    Christian Thibault
    Participant

    Trevor,

    I did try this:

    $sf_current_query = $searchandfilter->get($id)->current_query();
    $term = $sf_current_query->get_search_term();
    $count = $sf_current_query->found_posts;

    I returns the term, but not the count. How can I get the results count from the Search and Filter query?

    Thank you,

    Christian

    #254692

    In reply to: Results count


    Trevor
    Moderator

    The PHP would look like this, assuming the array returned by the wp_query() function in your child theme is named $query:

    Found <?php echo $query->found_posts; ?> Results

    #254439

    passion4social
    Participant

    Hello again,

    we are developing a website, and we are calling results from woocommerce products. All data from posts can be seen on the results page.

    However, suddenly, the search and filter fields disappeared. We thought at first it was ACF plugin that we installed, and it was not. It took hours to find out the problem. It is the WooCommerce plugin.

    Then we tried to use the default result page. It worked fine!

    So we ended up to cut pieces of the code to understand what was wrong. Finally we found a woocoomerce public action:

    <?php do_action(‘woocommerce_single_product_summary’); ?>

    This is somehow conflicting with the filter, as the content is loaded.

    Would you have any idea how go around it?

    here is the results.php code:

    <?php
    /**
    * Search & Filter Pro
    *
    * Sample Results Template
    *
    * @package Search_Filter
    * @author Ross Morsali
    * @link https://searchandfilter.com
    * @copyright 2018 Search & Filter
    *
    * 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
    *
    */

    // If this file is called directly, abort.
    if ( ! defined( ‘ABSPATH’ ) ) {
    exit;
    }

    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();

    ?>

    <?php
    /**
    * This is a reference from WooCommerce to load simple product data
    * Hook: woocommerce_single_product_summary.
    *
    * @hooked woocommerce_template_single_title – 5
    * @hooked woocommerce_template_single_rating – 10
    * @hooked woocommerce_template_single_price – 10
    * @hooked woocommerce_template_single_excerpt – 20
    * @hooked woocommerce_template_single_add_to_cart – 30
    * @hooked woocommerce_template_single_meta – 40
    * @hooked woocommerce_template_single_sharing – 50
    * @hooked WC_Structured_Data::generate_product_data() – 60

    do_action( ‘woocommerce_single_product_summary’ );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_title’, 5 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_rating’, 10 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_excerpt’, 20 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_meta’, 40 );
    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_sharing’, 50 );

    */
    ?>

    <div class=”course”>
    <div class=”course-main”>
    <div class=”course-image”><?php the_post_thumbnail(“small”); ?></div>
    <?php $price = get_post_meta(get_the_ID(), ‘_price’, true); ?>
    <div class=”course-price”><?php echo ‘<p class=”price”>£’ . number_format($price, 0, ‘.’, ‘.’) ; ?></div>
    <div class=”course-title”><?php the_title(); ?></div>
    <div class=”course-plus”>
    <div class=”purchase-button-bg”></div>
    <div class=”more-info-button-bg”></div>
    </div>

    </div>

    </div>
    <div class=”course-buttons”>
    <div class=”course-purchase”>
    <div class=”topics”>
    <span type=”button” onclick=”PurchaseFront()”>Purchase</span>
    <div class=”course-add content-inner”><div class=”course-summary”><?php do_action(‘woocommerce_single_product_summary’); ?></div></div>
    </div>
    </div>
    <div class=”course-more-info”>
    <div class=”topics”>
    <span type=”button” onclick=”MoreInfoFront()”>More Info +</span>
    <div class=”course-full-content content-inner”>
    <div class=”tab”>
    <input type=”button” value=”Description” title=”course-description-tab” onclick=”openService(event, ‘course-description-<?php echo get_the_ID();?>’)” class=”tab-layout tablinks” />
    <input type=”button” value=”Audience” title=”course-audience-tab” onclick=”openService(event, ‘course-audience-<?php echo get_the_ID();?>’)” class=”tab-layout tablinks” />
    <input type=”button” value=”Outcomes” title=”course-outcomes-tab” onclick=”openService(event, ‘course-outcomes-<?php echo get_the_ID();?>’)” class=”tab-layout tablinks” />
    <input type=”button” value=”Prerequisites” title=”course-prerequisites-tab” onclick=”openService(event, ‘course-prerequisites-<?php echo get_the_ID();?>’)” class=”tab-layout tablinks” />
    <input type=”button” value=”Licences” title=”course-licences-tab” onclick=”openService(event, ‘course-licences-<?php echo get_the_ID();?>’)” class=”tab-layout tablinks” />
    <input type=”button” value=”Certification” title=”course-certification-tab” onclick=”openService(event, ‘course-certification-<?php echo get_the_ID();?>’)” class=”tab-layout tablinks” />
    </div>
    <div id=”course-description-<?php echo get_the_ID()?>” class=”tabcontent” style=”display: block;”><?php echo the_content(get_the_ID(), ”, true); ?></div>
    <div id=”course-audience-<?php echo get_the_ID()?>” class=”tabcontent” style=”display: block;”><?php echo get_post_meta(get_the_ID(), ‘audience-shop’, true); ?></div>
    <div id=”course-outcomes-<?php echo get_the_ID()?>” class=”tabcontent” style=”display: block;”><?php echo get_post_meta(get_the_ID(), ‘outcomes-shop’, true); ?></div>
    <div id=”course-prerequisites-<?php echo get_the_ID()?>” class=”tabcontent” style=”display: block;”><?php echo get_post_meta(get_the_ID(), ‘prerequisites-shop’, true); ?></div>
    <div id=”course-licences-<?php echo get_the_ID()?>” class=”tabcontent” style=”display: block;”><?php echo get_post_meta(get_the_ID(), ‘licences-shop’, true); ?></div>
    <div id=”course-certification-<?php echo get_the_ID()?>” class=”tabcontent” style=”display: block;”><?php echo get_post_meta(get_the_ID(), ‘certification-shop’, true); ?></div>
    </div>
    </div>
    </div>
    </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”;
    }
    ?>

    #253899

    Trevor
    Moderator

    It would require an edit in the PHP template file being used. Inside the results container, you would need code like this:

    Found <?php echo $query->found_posts; ?> Results (assuming that your theme uses $query for the results array, otherwise it would need to be changed to match whether results array variable name your theme uses.

Viewing 10 results - 21 through 30 (of 254 total)