Forums Forums Search Search Results for 'the_field'

Viewing 10 results - 21 through 30 (of 64 total)
  • Author
    Search Results
  • #220782

    Trevor
    Participant

    Ah, OK.

    I think you should use our Shortcode method instead. See here and also follow the guide for customising:

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

    Then, either edit the results.php file yourself, or contact me and I will edit the results.php file for you. I think the content needs to be like this:

    if ( $query->have_posts() )
    {
    	?>
    	
    	<div class="ngo-list">	
    		<div class="table">
    				
                <table>
                    <tr>
    					<th>Name</th>
    					<th>Category </th>
    					<th>Website </th>
    					<th>Learn More </th>
    				</tr>
    	
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		?>
                    <tr>
    					<td><h5 class=""><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5></td>
    					<td><?php $term = get_field('ngo_category'); echo get_term($term)->name; ?></td>
    					<td><a href="<?php the_field('website'); ?>"><?php the_field('website'); ?></a></td>
    					<td><a href="<?php the_permalink(); ?>">View Details</a></td>
    				</tr>
    		<?php
    	}
    	echo paginate_links();
    	
    } ?>
                </table>
    					
            </div>
    	</div>	
    
    ?>
    #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?

    #220320

    Anonymous
    Inactive

    Thanks! That worked well.
    Just out of curiosity, my code works but I have such a rudimentary understanding of PHP I only want the fields “image” and “business_description” to display if it exists. This is what I got. How can I add that in or is there some post I can look at to figure it out. `<?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
    *
    */

    if ( $query->have_posts() )
    {
    ?>
    <?php
    $header_link = the_field(‘business_website_address_url’);
    ?>

    <?php
    while ($query->have_posts())
    {
    $query->the_post();

    ?>

    <div>
    <h2><a href=”<?php the_field(‘business_website_address_url’); ?>”><?php the_title(); ?></a></h2>
    <div class=”desc”><img src=”<?php the_field(‘image’); ?>”><p><?php the_field(‘business_description’) ?></p></div>
    <p class=”details”> Website: <a href=”<?php the_field(‘business_website_address_url’); ?>” target=”_blank”><?php the_field(‘business_website_address_url’) ?></a></p>
    <p class=”details”> Phone: <a href=”tel:<?php the_field(‘phone’); ?>”><?php the_field(‘phone’) ?></a></p>
    <p class=”details”> Booth: <?php the_field(‘booth_number’) ?></p>

    </div>

    <hr />
    <?php
    }
    ?>
    Page <?php echo $query->query[‘paged’]; ?> of <?php echo $query->max_num_pages; ?><br />

    <div class=”pagination”>

    <div class=”nav-previous”><?php next_posts_link( ‘More Exhibitors’, $query->max_num_pages ); ?></div>
    <div class=”nav-next”><?php previous_posts_link( ‘Previous Exhibitors’ ); ?></div>
    <?php
    /* example code for using the wp_pagenavi plugin */
    if (function_exists(‘wp_pagenavi’))
    {
    echo “<br />”;
    wp_pagenavi( array( ‘query’ => $query ) );
    }
    ?>
    </div>
    <?php
    }
    else
    {
    echo “No Results Found”;
    }
    ?>`

    #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.

    #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.

    #206079

    In reply to: Shortcodes in excerpt


    Trevor
    Participant

    Did you try wrapping that code in a do_shortcode function?

    <?php if( get_field('my_custom_field') ):?>
    <p>My Custom Field Value: <?php do_shortcode(the_field('my_custom_field')); ?></p>
    <?php endif; ?>

    I am not sure if that would work. Otherwise you may need to use PHP string functions to fetch the string as before, then split it up into before the button shortcode, the shortcode and the what comes after, and then handle them, with the shortcode being output in a do_shortcode function.

    #205982

    In reply to: Shortcodes in excerpt


    Anonymous
    Inactive

    Is the page loading using Ajax? If so, that will be the issue, as the player you are using needs reinitialising after an Ajax load. What player are you using?

    I am using Ajax to load the page. I am using standard WP audio shortcode.
    I turned Ajax off and all is good now. Thanks!

    <?php if( get_field(‘my_custom_field’) ):?>
    <p>My Custom Field Value: <?php the_field(‘my_custom_field’); ?></p>
    <?php endif; ?>

    thanks, I will try

    PS Very good support speed!

    #205978

    In reply to: Shortcodes in excerpt


    Trevor
    Participant

    Is the page loading using Ajax? If so, that will be the issue, as the player you are using needs reinitialising after an Ajax load. What player are you using?

    As to ACF fields. Let us assume it is a single value field use key is my_custom_field and the prefix required is My Custom Field Value, then the PHP is this:

    <?php if( get_field('my_custom_field') ):?>
    <p>My Custom Field Value: <?php the_field('cial_secteur'); ?></p>
    <?php endif; ?>
Viewing 10 results - 21 through 30 (of 64 total)