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 Search Results for 'results.php acf get_field'

Viewing 10 results - 1 through 10 (of 10 total)
  • Author
    Search Results
  • #240166

    In reply to: Numbered Pagination


    kiwicreative
    Participant

    Hi Trevor,

    I’m not sure where I define the ajax container. I copied the default results.php, pasted in an overriding template and made slight modifications to integrate Foundation CSS classes and pull in ACF field values.

    Here’s my results template 475.php

    <?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
     *
     */
    ?>
    
    <?php if ( $query->have_posts() ) : ?>
    
    <div class="grid-x grid-padding-x grid-margin-x resources-results-list">
    		
    	<?php 
    	
    	while ($query->have_posts()) : $query->the_post(); 
    	
    		$resource_link_type = get_field('resource_link_type');
    	
    		if( $resource_link_type == 'internal') :
    	
    			$link_dest = get_field('resource_internal');
    			$link_attr = '';
    	
    		elseif( $resource_link_type == 'external') :
    	
    			$link_dest = get_field('resource_external');
    			$link_attr = ' target="_blank"';
    	
    		elseif( $resource_link_type == 'download') :
    	
    			$link_dest = get_field('resource_download');
    			$link_attr = ' target="_blank" download';
    	
    		endif;
    	
    	?>
    		<div class="small-12 medium-6 large-4 cell">
    			<div class="resource-item">
    				<div class="resource-image text-center">
    					<?php the_post_thumbnail( 'full' ); ?>
    				</div>
    				<h3 class="resource-title"><?php the_title(); ?></h3>
    				<div class="resource-type"><?php the_field('resource_type'); ?></div>
    				<div class="resource-content">
    					<?php the_content(); ?>
    				</div>
    				<div class="resource-link">
    					<a href="<?php echo $link_dest; ?>" class="button"<?php echo $link_attr; ?>><?php the_field('resource_link_text'); ?></a>
    				</div>
    			</div>
    		</div>
    	<?php endwhile; ?>
    		
    </div>
    
    <div class="grid-x grid-padding-x pagination align-center">
        <?php /*
    	<div class="cell shrink nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
    	<div class="cell shrink nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
        */ ?>
        
        <div class="cell shrink">
            <?php numbered_pagination(); ?>
        </div>
        
    </div>
    	
    			
    <?php 
    
    else : 
    
    ?>
    <div class="grid-x grid-padding-x">
    	<div class="small-12 cell">
    		<span>No Results Found</span>
    	</div>
    </div>
    <?php endif; ?>

    Stefano
    Participant

    Hi,
    I’ve searched as long as possible in the forum.
    I’ve read the documentation.

    The ajax form search fields and reset, works well.
    But I can’t get infinite scrolls to work.

    I’ve tryed with shortcode. I’ve put the shortcode in the WP classic editor. I’ve copied results.php in a subfolder of my theme (that is elementor hello theme) and I pasted in, the code of the results-infinite-scroll.php template.
    In the settings the result url is filled etc etc.
    Nothing. Scrolling nothing happens.

    Then I’ve tryed with custom setting. I’ve set a custom template in my theme with the code of the results-infinite-scroll.php template customized.
    In the settings the result url is filled etc etc.
    Ajax container = #main
    Pagination Type is set to infinite scroll; show loading icon checkbox is checked, but it’s not loaded.
    Post result selector = .search-results-item (but I’ve tryed without it, too)
    Infinite Scroll Container: = empty (but I’ve tryed with #search-filter-results-list, too)
    I’ve tryed all the other fields of the Ajax Pagination setting section, but nothing.
    I’ve deactivated all plugin except ACF Pro, Custom post type UI and S&F Pro of course. Nothing
    I’ve changed the theme with a default one. Nothing.

    The page is on a live web site that I’m developing. I can give the url but not publicly

    Thanks in advance for your help

    My custom template code:

    <?php
    /*
    Template Name: Eventi
    */
    get_header(); 
    ?>
    <style>
    .content {
        width:1440px;
        margin:0 auto;
        padding:20px;
    }
    .search-results-wrapper {
        display:flex;
        flex-wrap: wrap;
    }
    .search-results-item {
      /*flex: 1 0 21%;*/
      padding: 20px;
      display: flex;
      flex-direction: column;
      flex-basis: 25%;
    }
    .content-wrapper {
      flex: 1;
    }
    .post-thumb {
        height:300px;
        width:100%;
        background-position:center;
        background-size:cover;
        border-radius: 0 80px 40px 80px;
        border: 1px solid #15255E;
    }
    .post-thumb .term {
        display:inline-block;
        padding:5px 20px;
        background-color:#ccc;
        color:#FFF;
        min-width:200px;
        text-align:center;
        font-size: 20px;
        font-weight: 500;
    }
    .post-content {
        display:none;
        font-size:1rem;
      color:#010326;
      padding-top:20px;
      width:100%;
    }
    .post-title {
        color: #009cd3;
        font-size: 28px;
        margin-top:30px;
    }
    .post-event-date,
    .post-event-place {
        font-size: 16px;
        font-weight: 400;
        color: #009cd3;
    }
    
    .search-results-wrapper .btn-wrapper {
        margin-top:30px;
    }
    .search-results-wrapper .toggle_btn {
        width:100px;
    }
    .search-results-wrapper .btn-hover-last {
        width:75px;
    }
    .search-results-wrapper .btn-hover-first {
        margin-right:40px;
    }
    .search-results-wrapper .btn-hover-wrapper {
      text-align:left;  
      position:relative;
      padding-right:20px;
      display:inline-block;
    }
    
    .search-results-wrapper .toggle-wrapper:after {
      content:"\f067";
      font-size: 16px;
      top: 0px;
      right: 0px;
      position: absolute;
      -webkit-transition: all .5s ease-out;
      -moz-transition: all .5s ease-out;
      -o-transition: all .5s ease-out;
      transition: all .5s ease-out;
      display: inline-block;
      font-style: normal;
      font-variant: normal;
      text-rendering: auto;
      -webkit-font-smoothing: antialiased;
      font-family: 'FontAwesome';
      color:#15255e;
    }
    .search-results-wrapper .toggle-wrapper.active:after {
      transform: rotate(-180deg);
      content:"\f068";
      color:#009ad2;
    }
    .search-results-wrapper .btn-hover-wrapper a
    {
      display:block;
      position:relative;
      cursor:pointer;
    }
    .search-results-wrapper .btn-hover-wrapper img
    {
       transition: opacity .25s ease-in-out;
       -moz-transition: opacity .25s ease-in-out;
       -webkit-transition: opacity .25s ease-in-out;
    }
    .search-results-wrapper .btn-hover-last {
        padding:0;
    }
    .search-results-wrapper .btn-hover-last a {
      transform: translateY(-3px);
    }
    .search-results-wrapper .btn-hover-wrapper .hover-image
    {
      position:absolute;
      top:0px;
      left:0px;
      opacity:0;
       transition: opacity .25s ease-in-out;
       -moz-transition: opacity .25s ease-in-out;
       -webkit-transition: opacity .25s ease-in-out;
    }
    
    .search-results-wrapper .btn-hover-wrapper:hover img
    {
     opacity:0; 
    }
    
    .search-results-wrapper .btn-hover-wrapper:hover .hover-image
    {
     opacity:1; 
    }
    
    </style>
    
    	
    	<div class="content">
    	
    		<div class="inner-content">
    
    			<main class="main" role="main" id="main">
    			    
    				
    				<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
                        <article id="post-<?php the_ID(); ?>" <?php post_class(''); ?> role="article" itemscope itemtype="http://schema.org/WebPage">
                        						
                        	<header class="article-header"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                        		<h1 class="page-title"><?php the_title(); ?></h1>
                            </header> <!-- end article header -->
    
                            <section class="entry-content" itemprop="text">
                        	    <?php the_content(); ?>
                        	</section> <!-- end article section -->
                        
                        </article> <!-- end article -->
                        
                     <?php endwhile; endif; ?>
                     
                    <?php wp_reset_query(); ?>
    
                     
                        
                	<div>
                		<?php echo do_shortcode('[searchandfilter id="1675"]'); ?>
                	</div>
    
                        <?php
                        
                        $args = array('post_type' => 'eventi');
                        $args['search_filter_id'] = 1675;
                        $query = new WP_Query($args);
                        
                        if ( $query->have_posts() ) {
                        ?>
                        
                        Found <?php echo $query->found_posts; ?> Results<br />
                        
                        	<div class="search-results-wrapper" id="search-filter-results-list">
                            	<?php
                            	while ($query->have_posts())
                            	{
                            		$query->the_post();
                            		$content = get_the_content();
                            		?>
                            		<div class="search-results-item search-filter-result-item">
                            			
                            			<div class="content-wrapper">
                                		    <?php 
                                				if ( has_post_thumbnail() ) :
                                				    $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'medium-large'); 
                                		    ?>
                                				<div class="post-thumb" style="background-image:url(<?=$featured_img_url ?>)">
                                				    <?php 
                                                        $terms = get_the_terms( $post->ID, 'tipologia' ); 
                                                        foreach($terms as $term) :
                                                    ?>
                                                            <span class='term' style="background-color:<?php the_field('tax_tipologia_color', 'tipologia' . '_' . $term->term_id) ?>">
                                                              <?php echo $term->name; ?>
                                                            </span>
                                                    <?php
                                                        endforeach;
                                                    ?>
                                				</div>
                                			<?php 
                                			    endif;
                                			?>
                                			<h2 class="post-title"><?php the_title(); ?></h2>
                                			<div class="post-event-date">
                                			    <span class="from-date"><?php the_field("start_date"); ?></span>
                                			    <?php 
                                			        if ( get_field("end_date") ) :
                            		            ?>
                                			            <span class="to-date"> - <?php the_field("end_date"); ?></span>
                                			    <?php       
                                			        endif;
                                			    ?>
                                			</div>
                                			<div class="post-event-place"><?php the_field("luogo"); ?></div>
                                        </div>
                                        
                                        <div class="btn-wrapper">
                                            <div class="btn-hover-wrapper toggle-wrapper btn-hover-first">
                                              <a class="toggle_btn" data-id="post-<?php the_ID(); ?>">  
                                                <img src="https://supernovae.kreas.it/wp/wp-content/uploads/2019/12/Scopri-di-piu-2.png" alt="Scopri di piu">
                                                <img src="https://supernovae.kreas.it/wp/wp-content/uploads/2019/12/Scopri-di-piu_over.png" class="hover-image" alt="Scopri di piu over">
                                              </a>
                                            </div>
                                            <div class="btn-hover-wrapper btn-hover-last">
                                              <a href="<?php the_field("event_url"); ?>" target="_blank" title="Scopri di piu">
                                                <img src="https://supernovae.kreas.it/wp/wp-content/uploads/2019/11/vai-al-sito-e1575911625135.png" alt="Vai al sito">
                                                <img src="https://supernovae.kreas.it/wp/wp-content/uploads/2019/11/vai-al-sito-over-e1575911641927.png" class="hover-image" alt="Vai al sito">  
                                              </a>
                                            </div>
                                            <div class="post-content toggle-content" id="post-<?php the_ID(); ?>">
                                                <?=$content ?>
                                            </div>
                                        </div>
                                        
                            		</div>
                            		
                        		<?php
                            	}
                            	?>
                        	</div>
                        <?php
                        }
                        else
                        {
                        	?>
                        	<div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>
                        		<span>Non sono stati trovati eventi</span>
                        	</div>
                        	<?php
                        }
                        ?>
    				
    			    					
    			</main> <!-- end #main -->
    			
    			
    
    			
    
    		</div> <!-- end #inner-content -->
    
    	</div> <!-- end #content -->
    
    <script>
    jQuery(document).on('click', ".toggle_btn", function(event){
        var post_id = jQuery(this).attr("data-id");
        jQuery(this).parent().toggleClass('active');
        jQuery("#" + post_id).toggle(500);
        event.preventDefault();
    });    
    </script>
    <?php get_footer(); ?>
    #219117

    Trevor
    Moderator

    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/

    #212123

    In reply to: Custome query


    Trevor
    Moderator

    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/

    #185960

    Trevor
    Moderator

    Ah. So, you are using the shortcode results method, and you want to display ACF data. The guide to customising the appearance of the results is here:

    https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results

    You will need to do that first and then use the ACF documentation to add your own HTML/PHP to output as you want. This search will give you some snippets already posted on our forum:

    https://support.searchandfilter.com/forums/search/results.php+acf+get_field/

    For example, this post (and thread):

    https://support.searchandfilter.com/forums/topic/output-acf-post-object-fields-in-results/#post-102009

    #139694

    Maria Perretgentil
    Participant

    Hi Trevor,

    Thanks to your amazing help, I was able to also make something like this work with that maps plugin you mention above.

    Here’s the maps code I placed on the results.php page in my child theme (the ACF field for the map ID is called “hotel_map_id”):

    <?php
    $map_sc_text='[wpgmza id=”5″ mashup=true mashup_ids=”‘;

    while ($query->have_posts())
    {
    $query->the_post();

    ?>
    <div>
    <h2>“><?php the_title(); ?></h2>

    <p><br /><?php the_excerpt(); ?> </p>
    <?php
    if ( has_post_thumbnail() ) {
    echo ‘<p>’;
    the_post_thumbnail(“small”);
    echo ‘</p>’;
    }
    ?>
    <p><?php the_category(); ?></p>
    <p><?php the_tags(); ?></p>

    </div>

    <hr />
    <?php

    $map_sc_text.=get_field(‘hotel_map_id’).’,’;
    }

    $map_sc_text.='” parent_id=”5″]’;
    do_shortcode($map_sc_text);

    ?>

    However, even though the functionality is perfect, I now get this error (only on the search and results page, not the whole site):

    Warning: Invalid argument supplied for foreach() in /wp-content/plugins/wp-google-maps-pro/wp-google-maps-pro.php on line 3570.

    Did you by any chance come across this issue when you were doing this? If so, how did you fix it?

    Thank you so so much!

    Maria

    #120750

    Trevor
    Moderator

    Yes, you can use get_field(). I have made many custom results.php templates for various ACF fields.

    #102009

    Trevor
    Moderator

    A lot of that you don’t need. You need to be careful of the type of field you are getting. For example, arrays are different. The ACF online manual is a big help. Below is an example results.php file that gets ACF fields and uses them:

    <?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() )
    {
    	?>
    	
    	Found <?php echo $query->found_posts; ?> Results<br />
    	Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />
    	
    	
    	 <div style="width:100%;">
    
    	
                
                   		<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
    	<div class="result">
    	
    		<?php if (get_field('property_main_image') != '') { ?>                     
             <img />" alt="" width="400px" />   
                       <div class="status"><?php echo get_field('status'); ?></div>
                       <div class="details">
                        
                           <?php
                           
                            echo '<h4>$' .  get_field('price') . ' </h4>';                           
                                                    
                            
    						echo '<p>' . get_field('address') . '<br>';
    						echo get_field('city') . ', '; echo get_field('state'); echo get_field('zip') . '</p>';   
    
    						echo '<p class="spex">' .  get_field('bedrooms') . ' BEDROOMS | '; echo get_field('bathrooms') . ' BATHROOMS<br>';
    	
    						echo '<span class="secondline">' .  get_field('square_footage') . ' SQ FT | '; echo get_field('garages') . ' CAR GARAGE</span>';
    
    	
    						echo '<span>MLS# ' .  get_field('MLS') . '</span></p>';?>
      					
      						
      					
      						<div class="linx">	
      							
      							<a href="#"><img src="/CreativeHomes/wp-content/uploads/2016/08/CH_Button_Photos_Grey.png" alt="see photo gallery" /></a> 
      							<a target="_blank">"><img src="/CreativeHomes/wp-content/uploads/2016/08/CH_Button_MapPin_Grey.png" alt="google map for location" /></a> 
      							<a target="_blank">"><img src="/CreativeHomes/wp-content/uploads/2016/08/CH_Button_Collateral_Grey.png" alt="brochure download" /></a>
      						</div><!--end linx-->
      					
      						<a>"><img src="/CreativeHomes/wp-content/uploads/2016/08/details-button.png" width="122" alt="details" /></a>
    
      					</div><!--end details-->
      	  							
      	
      				<div class="interact">
      					<span><?php the_favorites_button($post_id, $site_id); ?></span>
      					<span><img src="/CreativeHomes/wp-content/uploads/2016/08/check-icon.jpg" />Compare</span>
      					<span><?php if ( function_exists( 'ADDTOANY_SHARE_SAVE_KIT' ) ) { ADDTOANY_SHARE_SAVE_KIT(); } ?>Share</span>
    
      				</div><!--end interact-->  
      				                     
    			</div><!--end result-->
    
    		<?php
    	}
    	?>	
    	</div>				
    	
    	
    	
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }
    ?>
    #28577

    Philip Macaulay
    Participant

    Hi Ross

    Thanks for getting back to me. Actually I probably didn’t explain myself very well. All I wanted to do was return the results of some simple custom fields in the search results, which I have managed to do in my own clumsy hacking way, by using the get_field for ACF, which works great for me. But I’m having a strange issue with the search results, the post date, which I think is a standard result you would expect to see from your standard results.php template and which I have left in my ‘updated’ version is not automatically showing up – it’s really strange. If I set the CPT published date to something random like two weeks previous it shows in the results, but if I just create a new CPT it just doesn’t show up at all.

    I wonder if you have come across this issue before – I realise I should really start a new thread, and I will if there’s not a straight forward answer.

    Anyway this is my code for returning the Custom Fields with the post_date towards the end:

    while ($query->have_posts())
    {
    $query->the_post();

    ?>
    <div class=”searchresult”>

    <h2>“><?php the_title(); ?></h2>
    <?php $field = get_field(“location”, $post_id, $format_value);
    $value = get_field( “company” );

    if( $value ) {

    echo ‘<div class=”resultcompany”>’;
    echo ‘<h4 class=”resulttitle”>’ . “company” . ‘: </h3>’;
    echo ‘<h4 class=”resultvalue”> ‘ . $value . ‘</h3>’;
    echo ‘</div>’;
    }

    $field = get_field(“deadline”, $post_id, $format_value);
    $value = get_field( “location” );

    if( $value ) {

    echo ‘<div class=”resultlocation”>’;
    echo ‘<h4 class=”resulttitle”>’ . “location” . ‘: </h3>’;
    echo ‘<h4 class=”resultvalue”> ‘ . $value . ‘</h3>’;
    echo ‘</div>’;
    }

    $field = get_field(“deadline”, $post_id, $format_value);
    $value = get_field( “deadline” );

    if( $value ) {

    echo ‘<div class=”resultdeadline”>’;
    echo ‘<h4 class=”resulttitle”>’ . “deadline” . ‘: </h3>’;
    echo ‘<h4 class=”resultvalue”> ‘ . $value . ‘</h3>’;
    echo ‘</div>’;
    }
    ?>

    <p class=”resultpostdate”>Vacancy Posted: <?php the_date(); ?></p>

    </div>

    <?php
    }
    ?>

    Thanks in advance Ross!

    #13234

    In reply to: Complex template query


    Trisha Miller
    Participant

    Thanks for the reply Ross……I think the problem is that previously (before using the SP plugin or making any attempt to filter the results), I used the get_posts style of query in order to compare one of the meta keys holding a (expiration) date to the current date, and to not display results for those posts where the meta-value date had passed…..then I used a foreach loop and setup_postdata to access all the meta data. That query worked perfectly – returned results unless the date had passed. All was great until I was asked to add some live filtering of the results.

    And I did figure out (rather easily) how to use the meta data to setup the same comparison in the “advanced” setting in the SP plugin, so the SP query does weed out those posts whose meta date has passed, so all was good there – I did get the expected posts returned. The only thing was that the “results.php” file that displays the results has a custom query variable ($query->the_post) most likely using wp_query rather than get_posts, and that does not seem to work with setup_postdata – because as near as I can tell, setup_postdata only seems to work with ‘foreach’, not ‘while’ loops….and foreach seems only to work with get_posts.

    As mentioned, I’m not a coder, so there’s likely a better way to do what I’m trying to do, but it took me many, many days of research and testing to get my (old) query just right, it just wasn’t further filterable without your plugin.

    NOW I do have everything working just great, but using the ACF “get_field” and “the_field” instead of get_post_meta – formatting dates is working great too…..so really I’m a pretty happy camper today…..I just wish I was more skilled with programming, I might have found a cleaner way….

    But I really do love this plugin…..it’s very impressive. I’m off to give the free version (which I tested first) a great review on the repository and give a shout-out to the paid version, which is even better. I always do that when I find a worthy plugin. 🙂

Viewing 10 results - 1 through 10 (of 10 total)