Advertisement
AMEEKER

Genesis, CPT, ACF, Display Custom Fields in Excerpt

Aug 23rd, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** Hotel Excerpts
  2.  *
  3.  * Display an excerpt of address
  4.  * on Hotel CPTS using ACF.
  5.  *
  6.  * @author Angie Meeker
  7.  * @uses   Advanced Custom Fields
  8.  */
  9. remove_action( 'genesis_post_content', 'hotel_excerpt' );
  10. add_action( 'genesis_post_content', 'hotel_excerpt' );
  11. function hotel_excerpt() {
  12.     // Return if CPT Hotels
  13.     if ( is_post_type_archive( 'hotels' ) )
  14.    
  15.     // Store the address data
  16.     $hotel_excerpt_data = array(
  17.         'address_1' => get_field( 'Address_1' ),
  18.         'address_2' => get_field( 'street_address_2' ),
  19.         'po_box'    => get_field( 'po_box' ),
  20.         'city'      => get_field( 'city' ),
  21.         'state'     => get_field( 'state' ),
  22.         'zip'       => get_field( 'zip' ),
  23.         'phone'   => get_field( 'phone' ),
  24.         'website' => get_field( 'website' ),
  25.     );
  26.    
  27.     // Only output if we have location data
  28.     if( $hotel_excerpt_data ) {
  29.     echo '<div class="hotelexcerpt">';
  30.             if ( $hotel_excerpt_data['address_1'] ) {
  31.                 echo '<div class="location">' . esc_attr( $hotel_excerpt_data['address_1'] ) . '</div>';
  32.             }
  33.             if ( $hotel_excerpt_data['address_2'] ) {
  34.                 echo '<div class="location">' . esc_attr( $hotel_excerpt_data['address_2'] ) . '</div>';
  35.             }
  36.             if ( $hotel_excerpt_data['po_box'] ) {
  37.                 echo '<div class="location">' . esc_attr( $hotel_excerpt_data['po_box'] ) . '</div>';
  38.             }
  39.             if ( $hotel_excerpt_data['city'] ) {
  40.                 echo '<span>' . esc_attr( $hotel_excerpt_data['city'] ) . '</span>';
  41.             }
  42.             if ( $hotel_excerpt_data['state'] ) {
  43.                 echo '<span>, ' . esc_attr( $hotel_excerpt_data['state'] ) . '</span>';
  44.             }
  45.             if ( $hotel_excerpt_data['zip'] ) {
  46.                 echo '<span> ' . esc_attr( $hotel_excerpt_data['zip'] ) . '</span>';
  47.             }
  48.             if ( $hotel_excerpt_data['phone'] ) {
  49.                 echo '<div class="location">' . esc_attr( $hotel_excerpt_data['phone'] ) . '</div>';
  50.             }
  51.             if ( $hotel_excerpt_data['website'] ) {
  52.                 echo '<div class="location"><a href="' . esc_url( $hotel_excerpt_data['website'] ) . '">Visit Our Website</a></div>';
  53.             }
  54.             if ( $hotel_excerpt_data['email'] ) {
  55.                 echo '<div class="location"><a href="mailto:' . esc_attr( $hotel_excerpt_data['email'] ) . '">Email</a></div>';
  56.             }
  57.                 echo '</div>';
  58.     }
  59. if ( '' != $hotel_excerpt_data ) {
  60.         $hotel_excerpt_data = strip_shortcodes( $text );
  61.         $hotel_excerpt_data = apply_filters('the_content', $text);
  62.         $allowed_tags = '<p>,<a>,<em>,<strong>,<img>';
  63.         $hotel_excerpt_data = strip_tags($text, $allowed_tags);
  64.         $hotel_excerpt_data = str_replace(']]>', ']]>', $text);
  65.         $excerpt_length = 0; // 20 words
  66.        
  67.         $hotel_excerpt_data = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  68.     }
  69.     return apply_filters('the_excerpt', $text);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement