Forums Forums Search Search Results for 'get_field'

Viewing 10 results - 121 through 130 (of 188 total)
  • Author
    Search Results
  • #108331

    Anonymous
    Inactive
    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(504)->current_query();
    echo $sf_current_query->get_field_string("_sft_category");
    ?>

    The above code gets the current category, but how to do it without the extraneous word(s) before it?

    Thanks

    #102011

    Anonymous
    Inactive

    Great stuff, how come you are echoeing get_field instead of using the_field?

    The example you provided outputs single fields fine, but what would be some example code to use ACF’s Post Object?

    Using the example ACF site supplies doesnt work as expected.

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

    #99914

    In reply to: Empty result message


    Anonymous
    Inactive

    Hi Trevor,

    Thank you for your reply. I don’t know if you can call it an ‘own results template’ because in the settings you set a class, in my case .list, to show the results when you use the filter. I do have my own template for the loop to show the initial posts. Can I show you this template:

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

    When there are no results I don’t get the ‘else’ message and in the console I see an error that the main.js file is not found. I don’t know if I can use a link in the reply message but the page is: http://joemarque.nl/dev/bvd/bontvrijlijst-test/.

    Maybe you can see what I am doing wrong.

    Best regards,
    Joeri.

    #95975

    Anonymous
    Inactive

    I found some workaround, to display currently selected value:

    $tmp = $sf_current_query->get_array();
    echo $tmp["_sfm_character"]["active_terms"][0]["name"];
    

    But it may be a bug in get_field_string method from documentation, which is not working in my case:

    echo $sf_current_query->get_field_string("_sfm_character");

    #95973

    Anonymous
    Inactive

    Sorry for the mistake, I mean echo $sf_current_query->get_field_string("_sft_category"); with t

    I did things as in the documentation, but cant output any _sfm filters

    #95968

    Trevor
    Participant

    Do you mean echo $sf_current_query->get_field_string("_sft_category"); with a t and not an m?

    Does the guidance and examples in the documentation help?

Viewing 10 results - 121 through 130 (of 188 total)