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>";
}
}
?>
AnonymousInactive
Hi Trevor,
Thanks for the code, just to clarify my code before was working okay it was just when I added the additional lines for the feature that checks if the user has entered anything where it broke. This was my original code:
<?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
*
*/
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>";
}
?>
I try adding your code above and it shows results but it also shows results when nothing has been entered and the user first lands on the page?
Does that make sense?
Thanks,
James
AnonymousInactive
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.
Great to see this, but it would be better to test if the field has a value before echoing it, maybe like this:
<?php if( get_field('bfo') ):?>
<p>BFO: <?php the_field('bfo'); ?></p>
<?php endif; ?>
I will close this thread for now.
AnonymousInactive
Found the solution myself!
<?php echo get_field('bfo'); ?>
did the trick
I think I understand. You would probably be better off using our Shortcode display results method on a real WordPress page instead of creating your own archive template.
If your goal is to only shows posts that have the meta key ‘show_in_a_z_list’ set a ‘1’ then you can do this in the Post Meta settings tab of the form. It might need to look like this:
https://www.screencast.com/t/2y2xrZyoYM
OR this (I am not sure which would work):
https://www.screencast.com/t/BoMkAG3yHi
If you need to modify our results.php template the guide is here:
https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results
If you need to output the value of an ACF field, and give it a label, the code shown in this post might help:
https://support.searchandfilter.com/forums/topic/output-acf-post-object-fields-in-results/#post-102009
You may find other posts with snippets with this forum search:
https://support.searchandfilter.com/forums/search/results.php+acf+get_field/
AnonymousInactive
Hi there,
I can get things working if I use the shortcode approach, utilising SAF’s own templates. However, I need to filter results displaying on the archive page, there is a basically an ACF checkbox ‘Show on the A-Z page’ (show_in_a_z_list), so I basically need to try and get SAF working with my custom archive page, unless I can make use of ACF on SAF’s template file?
Here is the code in my template, the SAF’s filters display, I just can get the AJAX side of things working, appreciate any help…
<?php
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'brands',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'show_in_a_z_list',
'value' => '1',
'compare' => '=',
),
),
));
if( $posts ): ?>
<?php echo do_shortcode( '[searchandfilter id="1132"]' ); ?>
<?php echo do_shortcode( '[searchandfilter id="1132" show="results"]' ); ?>
<section class="blocks">
<?php $i = 1; ?>
<?php foreach( $posts as $post ):
setup_postdata( $post );
?>
<div class="block-<?php echo $i++; ?>">
<a href="<?php the_permalink(); ?>">
<article>
<?php $image = get_field( 'image' ); ?>
<?php if ( $image ) { ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php } ?>
</article>
</a>
</div>
<?php endforeach; ?>
</section>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
Hi Michal
In regards to your original question, about prepending posts to the results array.
I don’t think it’s possible.
S&F uses a WP_Query
which is the WP way of generating a query, with the results as valid post objects.
There are no WP_Query params that we can use (in our sf_edit_query_args
filters, which is basically a filter for WP_Query
args) to do this.
The only way I could see you doing it, is in your results template.
You could run a query for the posts you want, and then combine it with the results from S&F.
I’m afraid achieving this specifically would be out of scope of support, but the above would be the general logic.
You also mentioned being able to do this only when a specific taxonomy is selected, and that can be done with the info from your second question:
You wanted to get the IDs of the terms.
If you use get_array
instead of get_field_string
you’ll see that taxonomies have IDs as well as slug and label – https://searchandfilter.com/documentation/accessing-search-data/#getan-array-offilterswithvalues-and-labels.
I hope the above is clear!
Thanks
AnonymousInactive
I have another topic regardless this one.
For example, my search query have custom taxonomy named “product_type”.
I’m using this line to retrive what kind of “product_type” is retrived right now:
$searchProductType = $sf_current_query->get_field_string("_sft_product_type");
However, is there any option to get ID of searched taxonomy instead of “Product Type: Name” ?