Forums Forums Search & Filter Pro Preselecting taxonomy?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #57011

    Ok, 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(); 
    ?>
    Trevor
    #57021

    This works for you. Kudos! Can I close the thread as self-resolved?

    Anonymous
    #57348

    Hi Trevor, would S&F do this out of the box or do we need to follow Samantha’s advice?

    Trevor
    #57362

    You would need to follow Samantha’s advice, as it cannot do it out of the box.

Viewing 4 posts - 1 through 4 (of 4 total)