• Hi,
    im using advanced custom fields https://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;
    }
  • The topic ‘catch_that_image & advanced custom fields’ is closed to new replies.