Forums Forums Search Search Results for 'get_field('

Viewing 10 results - 61 through 70 (of 90 total)
  • Author
    Search Results
  • #138347

    Trevor
    Participant

    There is no set answer for a question like that. It first depends, in the form settings, what Display Results Method you are using. In turn, this will determine what template php file you are using, as you code will need to fetch the data from the ACF field. However, javascript is not the way. Use PHP instead to fetch the ACF data, and then create some inline CSS based on what is fetched. I wrote something like this a while ago, where on each post the user could select an image to be used as a parallax background image at the top of the post. The code looked like this (used in the loop part of the page template):

    <?php
    $banner_image = get_field('banner_image');
    if ( !empty($banner_image) ) {
      echo '<style>.banner-image-wrapper {background-image: url("' . $banner_image['url'] . '");background-repeat: no-repeat;background-size: cover;}</style>';
    } else {
      echo '<style>.banner-image-wrapper {display: none;}</style>';
    }
    ?>

    and there is a row in the template that has that class attached.

    #136864

    Anonymous
    Inactive

    Hi, finally we have done to install the function with your suggestion.
    I have put the search-filter/result.php within my theme and list page is seemed to be fine though, the link displayed in the list are weird.

    After choosing some checkboxes and do search, result is showed up.
    And the url comes with some parameter of the search.
    and, the link within result index items have the parameters of the search after its own url.

    the result url is:
    http://blog.grphca.jp/visca_dev2/shinsatsuken/?_sft_variety=photo,animal

    and the link within the result index is:
    http://blog.grphca.jp/visca_dev2/idcard/pv08-28r/?_sft_variety=photo,animal

    result.php uses this code below for that:

    <a href="<?php the_permalink(); ?>" title="デザイン<?php the_title(); ?>">
    <?php $image = wp_get_attachment_image_src(get_field('test'), 'full');?>
    <img src="<?php echo $image[0]; ?>" alt="<?php echo get_the_title(get_field('test')) ?>" />
    </a>

    How can I get the correct url of the result?

    #128266

    Trevor
    Participant

    As I have not seen this requested before, can I assume that you have portfolio items, maybe as a Custom Post Type, and one field (probably a custom field) is the ‘external project URL’?

    If that is so, it is probably a meta key. You can test this in your search form by adding a Post Meta object to the form, make it a dropdown select, find the meta key name from the list, make the choices a manual selection, not automatic (which is the default), and there is then a search button/function to find the values already stored. If they look right, then you have found the key name.

    Then you need to use the standard WordPress codex method to call in a value for a custom field, like this:

    <?php echo get_post_meta( get_the_ID(), 'external_project_url', true ); ?>
    

    Depending on the actual key name. Note that fields made with specific plugins sometimes have different functions to retrieve the data, as does ACF for instance (using get_field()).

    #120750

    Trevor
    Participant

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

    #119857

    Anonymous
    Inactive

    The custom content is added in a custom field in the back-end and then called in results.php, before the loop as follows:

    <?php if( get_field('luxury_holidays_content') ): ?>
    
    	<div class="masonry-layout-panel custom-content">
    			
    		<?php the_field('luxury_holidays_content'); ?>
    		
    	</div>
    	
    <?php endif; ?>

    Strangely, if I hard code the custom content in results.php, it is always visible. However, if I call it in PHP as above, it gets removed when a search or form reset is performed.

    #114508

    Trevor
    Participant

    I would have thought you would simply use the Pods field() function, like this:

    <?php echo field('resumo_objectivos');?>
    

    But I am not familiar with the Pods plugin. This is so much easier in ACF, which would be this:

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

    In ACF, you can optionally specify to Post ID (using get_the_ID(), and the format), but if yu don’t, it assumes the ID of the current post in the loop. The code example that I can see assume you will run the loop from Pods, which is not helpful.

    #102009

    Trevor
    Participant

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

    Anonymous
    Inactive

    Sorry for the badly formatted code, cant see where to edit my post. Here it is formatted a little more readable:

    <?php
    while ($query->have_posts())
    {
    $query->the_post();
    
    ?>
    <tr>
    <td>
    <?php
    
    $post_object = get_field('customer');
    
    if( $post_object ): 
    
    // override $post
    $post = $post_object;
    setup_postdata( $post ); 
    
    ?>
    <?php the_title(); ?>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>
    
    </td>
    <td><?php the_date(); ?></td>
    <td><?php echo the_ID(); ?></td>
    <td><?php echo the_field('reg_no'); ?></td>
    </tr>
    <?php
    }
    ?>
    #99933

    In reply to: Empty result message


    Trevor
    Participant

    Ah, I see why. You are looping through custom terms one after the other, and only doing the actual wp_query inside each loop. That way you can have only one no results for each custom terms (the alphabet letters) or none at all. So, instead you have a test variable and set this to 0. Every time you find results in each loop, you increment that variable. If it is still 0 at the end, then no results were found:

    <?php
    $custom_terms = get_terms('alfabet');
    $empty_test = 0;
    if (!empty($custom_terms)) {
      foreach($custom_terms as $custom_term) {
      wp_reset_query();
        $args = array(
          'post_type' => 'bontvrijlijst',
          'search_filter_id' => 7242,
          'posts_per_page' => -1,
          'orderby'=> 'title',
          'order' => 'ASC',
          'tax_query' => array(
            array(
              'taxonomy' => 'alfabet',
              'field' => 'slug',
              'terms' => $custom_term->slug,
            ),
          ),
        );
    
        $loop = new WP_Query($args);
        if($loop->have_posts()) {
    					$empty_test++;
          echo '<div id="' . $custom_term->slug . '" class="alfabet-letter-wrap"><div class="alfabet-letter">'.$custom_term->name.'</div><ul class="members">';
          while($loop->have_posts()) : $loop->the_post();
            $company_link = get_field('url');
            echo '<li class="member"><a href="'. $company_link .'" target="_blank">'.get_the_title().'</a></li>';
          endwhile;
          echo '</ul></div>';
    				}
      }
    }
    if ($empty_test > 0) {
    	  echo '<p><strong>Er zijn geen bedrijven die voldoen aan deze zoekopdracht. Probeer het opnieuw.</strong></p>';
    }
    ?>
    #99926

    In reply to: Empty result message


    Trevor
    Participant

    See if this fixes the nor results message:

    <?php
    $custom_terms = get_terms('alfabet');
    if (!empty($custom_terms)) {
      foreach($custom_terms as $custom_term) {
      wp_reset_query();
        $args = array(
          'post_type' => 'bontvrijlijst',
          'search_filter_id' => 7242,
          'posts_per_page' => -1,
          'orderby'=> 'title',
          'order' => 'ASC',
          'tax_query' => array(
            array(
              'taxonomy' => 'alfabet',
              'field' => 'slug',
              'terms' => $custom_term->slug,
            ),
          ),
        );
    
        $loop = new WP_Query($args);
        if($loop->have_posts()) {
          echo '<div id="' . $custom_term->slug . '" class="alfabet-letter-wrap"><div class="alfabet-letter">'.$custom_term->name.'</div><ul class="members">';
          while($loop->have_posts()) : $loop->the_post();
            $company_link = get_field('url');
            echo '<li class="member"><a href="'. $company_link .'" target="_blank">'.get_the_title().'</a></li>';
          endwhile;
          echo '</ul></div>';
        } else {
      echo '<p><strong>Er zijn geen bedrijven die voldoen aan deze zoekopdracht. Probeer het opnieuw.</strong></p>';
        }
      }
    }
    ?>

    I think the else was in the wrong place.

Viewing 10 results - 61 through 70 (of 90 total)