Support

Account

Home Forums General Issues getting a fatal error (recently)

Solving

getting a fatal error (recently)

  • Hi,

    i’m using following script to fetch the first image of a repeater:

    <? query_posts('cat=4'.'&showposts=4&posts_per_page=4'); 	// latest blog story?>
        <?php while (have_posts()) : the_post(); ?>
    
    <?php
    $main_field = get_field('beelden');
    $first_img = $main_field[0]['beelden']['url'];
    ?>
    
    <a href="<?php the_permalink() ?>"><img src="<?php echo $first_img ?>"/></a>
    
    	<?php endwhile; ?>

    recently, i’ve been getting this error:

    Fatal error: Cannot use string offset as an array in /home/pxlwemg122/domains/manufracture.be/public_html/wp-content/themes/sandbox/category-blog.php on line 40

    any ideas? this has worked perfectly (and still does on a other website!) in the past.

    thanks
    Mathieu

  • I think your issue is that you have a repeater field with the name of “beelden” but also seem to have a subfield within that repeater with the same name?

  • Hi @mathieu

    In case you are using a repeater, I would recommend that you use a the standard repeater loop to access the repeater rows.

    <?php
    
    // check if the repeater field has rows of data
    if( have_rows('repeater_field_name') ):
    
     	// loop through the rows of data
        while ( have_rows('repeater_field_name') ) : the_row();
    
            // display a sub field value
            the_sub_field('sub_field_name');
    
        endwhile;
    
    else :
    
        // no rows found
    
    endif;
    
    ?>
    

    If you just want the first row, you can introduce custom code to only pick the first row.

    I hope this helps.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘getting a fatal error (recently)’ is closed to new replies.