Forums Forums Search Search Results for 'get_field('

Viewing 10 results - 31 through 40 (of 90 total)
  • Author
    Search Results
  • #220392

    Trevor
    Participant

    So, if I understand you correctly, you want to conditionally show this part:

    <div class="desc"><img src="<?php the_field('image'); ?>”><p><?php the_field('business_description') ?></p></div>

    so, it would be this:

    <?php if (get_field('image')) {?>
    <div class="desc"><img src="<?php the_field('image'); ?>”><p><?php the_field('business_description') ?></p></div>
    <?php }?>

    This uses get_field to see if the image field has anything in it, and only outputs that bit if it does. I am assuming here that if the image exists, so will the description.

    I hope that helps?

    #220031

    Trevor
    Participant

    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>";
    }
    }
    ?>
    #219986

    Anonymous
    Inactive

    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

    #213056

    Trevor
    Participant

    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.

    #213032

    Anonymous
    Inactive

    Found the solution myself!

    <?php echo get_field('bfo'); ?>

    did the trick

    #212046

    Anonymous
    Inactive

    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; ?>

    Anonymous
    Inactive

    Hi,

    I have a search form set which targets a custom post type and loads the results in the custom post type archive. The search is working as normal however, the infinite scrolling doesn’t seem to work and when I change the results per page it doesn’t change on the results page.

    The custom post type archive is using the standard loop like so:

    Can you help please?

                     <div class="entry-content">
    
    <div class="tender-main-wrapper">
    
     <div id="searchtenders">
    	 	<?php echo do_shortcode('[searchandfilter id="3059"]'); ?>
    </div>
    
     <div class="tender-opportunity-panel">
    
      	<?php
    
    			// Start the loop.
    			$count = 1;
    
    			while ( have_posts() ) : the_post();
    
    				echo '<div class="'.$post->ID.' tender-oppor">';
    
    				echo '<div class="tender-desc">';
    					echo '<h2>'.get_field('opportunity').'</h2>';
    					echo '<p class="lead">' .get_field('funding_organisation').'</p>';
    					echo '<p><strong>Amount available:</strong> ' .get_field('amount_available').'</p>';
    					echo '<p><strong>Geographical Coverage:</strong> ' .get_field('geographical_').'</p>';
    					echo '<p><strong>Contract Duration:</strong> ' .get_field('contract_duration').'</p>';
    					echo '<p><strong>Deadline:</strong> ' .get_field('deadline').'</p>';
    					echo '<p><strong>Other notes:</strong> ' .get_field('other_notes').'</p>';
    					echo '<a class="btn readmore-link" target="_blank" href="' .get_field('hyperlink').'">Read more</a>';
    				echo '</div>';
    
    				echo '<div class="tender-cta">';
    				echo '
    						 <a class="btn btn-primary" target="_blank" href="'.site_url().'/contact-a-bid-writer/?ref='.get_the_title().'">Contact a Bid Writer</a>';
    				echo '</div>';
    
    				echo '</div>';
    
    			// End the loop.
    			$count++;
    			endwhile;
    ?>
       </div>
    
     </div>
    #209600

    Anonymous
    Inactive

    Hi Trevor,

    Thanks so much! I understand this is outside your support and your suggestion on how I would theoretically was EXACTLY what I needed to make this happen. I was able to get this to happen following your suggestion.

    I saw some others that were trying to do this, so I wanted to post my code in case in might help someone else. This code is using the Custom query output, so this code is placed within my custom template. It’s commented and should hopefully make sense to someone who’s trying to achieve something similar. It should be noted that for this client, it made the most sense for the posts be sorted ASCENDING by DATE, rather than the default DESCENDING. I imagine if you wanted/needed to use DESCENDING, then you would need to base the foreach and conditionals off of next_post instead of prev_post:

    <div id="faqloop">
    
            <?php
            $args = array(
             'search_filter_id' => 8836
           );
            $faqs = new WP_Query($args);
            if ($faqs->have_posts() ) : $count=0;
              while ($faqs->have_posts() ) : $count++;
                $faqs->the_post();
    
                //Custom Fields
                $question = get_field( 'faq_question' );
                $answer = get_field( 'faq_answer' );
    
                // Adjacent Posts, IDs and Terms
                $prev_post = get_previous_post();
                $next_post = get_next_post();
                $next_post_id = $next_post->ID;
                $prev_post_id = $prev_post->ID;
                $prev_terms = get_the_terms( $prev_post_id, 'faq_category' );
                $terms = get_the_terms( $post->ID, 'faq_category' );
    
                // Create variable containers for the post IDs
                $term_slug = array();
                $prev_term_slug = array();
                $term_name = array();
    
                // Current tax loop
                foreach($terms as $term) {
                  $term_slug =  $term->slug;
                  $term_name =  $term->name;
                }
                //Adjacent Post tax loop
                foreach($prev_terms as $prev_term) {
                  $prev_term_slug =  $prev_term->slug;
                } ?>
    
    <?php //Echo term title if it's different than previous term OR is the last post in the loop
    if($prev_term_slug !== $term_slug || !$prev_post){ ?>
      <div class="faq-section--header <?php echo $term->slug; ?>">
       <h3><?php echo $term_name; ?></h3>
     </div>
    <?php } ?>
    
    <div class="faq-section--questions">
      <div class="faq-entry">
        <div class="faq-entry--question">
          <i class="faq-toggle"></i><span><?php echo $question; ?></span>
        </div>
        <div class="faq-entry--answer">
          <?php echo $answer; ?>
        </div>
      </div>
    </div>
    
    <?php endwhile; ?>
    <?php else: ?>
      <span data-search-filter-action='infinite-scroll-end'>No FAQs match that search or combination</span>
    <?php endif;?>
    <?php wp_reset_postdata(); ?>
    </div>
    #208613

    Trevor
    Participant

    First, make sure that you followed the guide for customization here:

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

    Then, editing the code, it would looks something like this:

    <?php if( get_field('flow_rate') ):?>
    <p>Flow Rate: <?php the_field('flow_rate'); ?></p>
    <?php endif; ?>

    Should be all you need.

    #206182

    In reply to: Shortcodes in excerpt


    Trevor
    Participant

    I changed the code to this:

    <?php if( get_field('purchase') ):?>
    <p><?php echo do_shortcode(get_field('purchase')); ?></p>
    <?php endif; ?>
Viewing 10 results - 31 through 40 (of 90 total)