-
AuthorSearch Results
-
September 21, 2020 at 2:04 pm #260159
In reply to: Results showing up twice
AnonymousInactiveI’ve updated so more in line with original
<?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();?>
<div>
<?php get_template_part(‘template-parts/content’, get_post_type()); ?></div>
<?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”;
}
?>September 16, 2020 at 2:33 am #259571In reply to: Can’t Get a Results Count with Oxygen Builder
AnonymousInactiveLiterally 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!
August 31, 2020 at 2:31 pm #257846In reply to: How to hide search results count?
TrevorParticipantIf 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.
August 21, 2020 at 10:42 am #256885In reply to: No search results
TrevorParticipantI 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 namedsearch-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>
August 3, 2020 at 3:33 pm #254877In reply to: Count for All Items
TrevorParticipantAll 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;
July 31, 2020 at 12:45 pm #254727In reply to: Results count
AnonymousInactiveTrevor,
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
July 31, 2020 at 11:57 am #254714In reply to: Results count
AnonymousInactiveTrevor,
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
July 31, 2020 at 10:18 am #254692In reply to: Results count
TrevorParticipantThe 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
July 27, 2020 at 10:39 am #253899In reply to: How to display total search result?
TrevorParticipantIt 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.July 13, 2020 at 5:18 pm #252657In reply to: No results found
TrevorParticipantThis line makes the ‘found x results of x’ part:
Found <?php echo $query->found_posts; ?> Results<br />
So delete that line?
This line displays Categories:
<p><?php the_category(); ?></p>
So, delete that?
This line displays Tags:
<p><?php the_tags(); ?></p>
The coding is simple and self evident thus far, yes?
This line displays the Post date:
<p><small><?php the_date(); ?></small></p>
To make the image smaller, change this:
the_post_thumbnail("small");
to this:
the_post_thumbnail("thumb");
-
AuthorSearch Results