WordPress.org

Ready to get started?Download WordPress

Forums

catch_that_image & advanced custom fields (1 post)

  1. gerbsi
    Member
    Posted 1 year ago #

    Hi,
    im using advanced custom fields http://www.advancedcustomfields.com to display images, Im using a repeater field.
    Im using the catch_that_image function to get the first image from each post — but id like to grab the first image from the 'bilder_bxslider' field. Ive benn trying a bit but without luck.

    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches[1][0];
    
    	if( get_field('bilder_bxslider') ):
    		while( has_sub_field('bilder_bxslider') ):
    			$first_img = the_sub_field('bildsnurra');
    		endwhile;
    	endif;
    
      if(empty($first_img)) {
        $first_img = bloginfo( 'template_url' ).'/images/default.jpg'; 
    
      }
      return $first_img;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic