Forums › Forums › Search & Filter Pro › Preselecting taxonomy?
- This topic has 4 replies, 3 voices, and was last updated 8 years, 2 months ago by Trevor.
Viewing 5 posts - 1 through 5 (of 5 total)
-
Anonymous(Private) September 8, 2016 at 5:43 pm #57005
Hi there,
The plugin works great as a default blog page.
What we would also like is to also use it on other pages to display posts with a certain term from a custom taxonomy.
Is it possible to preselect a term, so that only posts from that term are displayed by default but the visitor still has the option to choose other terms and expand the search?
These pages exist and have the taxonomy id set as a custom field (using ACF) so a solution using this would be perfect.
Anonymous(Private) September 8, 2016 at 7:47 pm #57011Ok, so I managed selecting the checkbox with some jQuery added via functions.php:
//Select sector in posts filter add_action('wp_footer', 'sectorpostsfilter'); function sectorpostsfilter(){ if (function_exists('get_field')) : $sectorobject = get_field('taxonomy_sector'); $sectorid = $sectorobject->term_id; if ($sectorid) : ?> <script type='text/javascript'> jQuery = jQuery.noConflict(); jQuery(function( $ ) { $('.sf-item-<?php echo $sectorid; ?> input').prop('checked', true); }); </script><?php endif; endif; }
And by altering the query within the template:
<?php if (function_exists('get_field')) : $sectorobject = get_field('taxonomy_sector'); $sectorslug = $sectorobject->slug; endif; $loop = new WP_Query( array( 'sectors' => $sectorslug ) ); while ( $loop->have_posts() ) : $loop->the_post(); get_template_part( 'loop', 'post' ); endwhile; wp_reset_postdata(); ?>
-
AuthorPosts
Viewing 5 posts - 1 through 5 (of 5 total)