Support Forums

The forums are closed and will be removed when we launch our new site.

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

Forums Forums Search & Filter Pro ACF posts not displaying

Tagged: ,

Viewing 6 posts - 1 through 6 (of 6 total)
  • Lee Bollu
    #245977

    Hello. I am trying to create a range filter on my site.

    I have used the meta field in Search and Filter pro and linked it to a number field in ACF. I have set the results to display “Custom” and created a custom template which runs my ACF loop. I have used the code below to pull the posts through as per the custom documentation.

    <?php
    $args = array('post_type' => 'workspace');
    $args['search_filter_id'] = 183;
    $query = new WP_Query($args);  ?>
    
    <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    /// My results
    
    <?php endwhile; else: ?>
    Sorry no posts. 
    <?php endif; ?>
    
    This shows no results. I have also tried using the "as an archive" option and it is still not working... Here is all my code, should it be of help .
    
    <?php get_header(); ?>
    <?php /* Template Name: Property Results */ ?>
    
    	<header>
    		<div class="container">
    			<div class="section group">
    				<div class="col span_8_of_12">
    					content
    				</div>
    			</div>
    			<!--Close .section-->
    		</div>
    		<!--Close .container -->
    	</header>
    	<!--Close header-->
    
    	<div class="container">
    		<?php echo do_shortcode('[searchandfilter id="183"]'); ?>
    	</div>
    
    	<div class="full-width lgrey-bg">
    		<div class="container">
    
    			<div class="section group property-promo-wrapper">
    				
    				<?php
    
    				$args = array('post_type' => 'workspace');
    				$args['search_filter_id'] = 183;
    				$query = new WP_Query($args);
    
    				?>
    
    				<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    					<div class="col span_6_of_12 property-promo">
    
    						<?php if( have_rows('images') ): ?>
    
    							<div class="owl-carousel owl-promoproperty">
    
    								<?php while( have_rows('images') ): the_row(); 
    
    									$image = get_sub_field('image');
    									?>
    
    									<div><img />"></div>
    								
    								<?php endwhile; ?>
    
    							</div>
    							<!-- Close .property-promo .images -->
    
    						<?php endif; ?>
    
    						<div class="info">
    
    							<h4><strong><?php the_title( '' ); ?></strong>
    							<br>– <strong><?php the_field('location'); ?></strong></h4>
    
    							<?php if( have_rows('nearby_stations') ): ?>
    
    								<ul class="rail">
    
    									<?php while( have_rows('nearby_stations') ): the_row(); 
    
    									$station_name = get_sub_field('station_name');
    									$distance_to_workspace = get_sub_field('distance_to_workspace');
    									$type_of_station = get_sub_field('type_of_station');
    									?>
    
    									<li class="<?php echo $type_of_station; ?>"><?php echo $station_name; ?> <?php echo $distance_to_workspace; ?></li>
    										
    									<?php endwhile; ?>
    								</ul>
    								<!-- Close .rail -->
    
    							<?php endif; ?>
    
    							<div class="stats">
    								<div class="section group">
    									<div class="col span_7_of_12">
    										<ul>
    											<li>size<br><strong><?php the_field('square_foot'); ?> sq ft</strong></li>
    											<li>per month<br><strong>£<?php the_field('price_per_month'); ?></strong></li>
    											<li>people<br><strong><?php the_field('people'); ?></strong></li>
    											<li>per year<br><strong>£<?php the_field('price_per_year'); ?></strong></li>
    										</ul>
    									</div>
    									<div class="col span_5_of_12">
    										<p><a>">Download brochure</a></p>
    										<a href="#"><div class="button button_a">Enquire</div></a>
    									</div>
    								</div>
    								<!-- Close .section -->
    							</div>
    							<!-- Close .stats -->
    						</div>
    						<!-- Close .info -->
    
    					</div>
    					<!-- Close .property-promo col -->
    
    				<?php endwhile; else: ?>
    					<h2>We have no properties to show at the moment</h2>
    					<p>Please subscribe to our mailing list to be the first to hear about new workspaces.</p>
    					<br>
    					<a href=""><div class="button button_a">Enquire</div></a>
    				<?php endif; ?>
    
    			</div>
    			<!--section -->
    		</div>
    		<!--container -->
    	</div>
    	<!--full-width -->
    
    <?php get_footer(); ?>
    Trevor Moderator
    #246000

    Are you able to send me a live link/URL to your search page so I can take a look?

    In selecting the Meta Key name, note a ‘gotcha’ with ACF ….

    … it makes 3 meta keys per field, like this (in this example for a field named ‘land’):

    #1 _land
    #2 field_52f0fc4334f52
    #3 land

    In our Meta Key selection list, you need to use key #3, without the underscore at the start of the key name. If you choose #1 by mistake, in the field choices you will see the name of #2.

    Lee Bollu
    #246091

    Hi, Trevor thank you for your reply. Ah. I did not see that.

    I have changed the filter to the non-underscore option and its still not showing. Looking at the page source, the loop fails to load and everything below it is just blank in the source code.

    The site is only working locally at the moment so unable to share a link.

    Is there a way of using the non-custom page template and just the standard loop with ACF content?

    Lee

    Trevor Moderator
    #246296

    If you want ACF fields to display in the results, you will need to code it. I cannot see any obvious errors in your code, but you need to follow standard debugging methods to find where it is failing. One thing I see that you are not doing is to test for the existence of the variable before using it.

    The method I would use is to reduce the code to a much smaller amount, thus not outputting a lot, test it, add a bit in, test it, and so on.

    It will not be our plugin causing this though, it will be your code.

    Lee Bollu
    #246378

    Fixed! It was where I was copying your support code and my loop was named slightly different. $query vs $the_query

    Trevor Moderator
    #246385

    Thanks for letting me know. I will close this thread for now.

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

The topic ‘ACF posts not displaying’ is closed to new replies.