Support

Account

Home Forums Front-end Issues Problem with setup_postdata only on archive page

Solved

Problem with setup_postdata only on archive page

  • I use 2 custom posts types ‘location’ and ‘event’. (An event can be linked with one or more location.)

    On my index.php and archive-event.php and single-event.php I have this piece of code :

    <article>
       <h2><?php the_title(); ?></h2>
       <?php $posts = get_field('location_event');
       if( $posts ): ?>
          <ul>
          <?php foreach( $posts as $post): ?>
          <?php setup_postdata($post); ?>
             <li><?php the_title(); ?></li>
          <?php endforeach; ?>
          </ul>
          <?php wp_reset_postdata(); ?>
       <?php endif; ?>
    </article>

    It works fine on my index.php and single-event.php but on my archive-event.php page it works only with my first article… I have this code error after the first article :

    Notice: Undefined offset: 1 in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 3680
    Notice: Trying to get property of non-object in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 4553
    Notice: Trying to get property of non-object in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 4555
    Notice: Trying to get property of non-object in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 4557
    Notice: Trying to get property of non-object in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 4558
    Notice: Trying to get property of non-object in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 4569
    Notice: Trying to get property of non-object in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 4577
    Notice: Trying to get property of non-object in /Users/marcaurele/Documents/Sites/wordpresstest/wp-includes/query.php on line 4594

    Since this morning, I’m totally lost…

  • It appears that disable and enable the plugin have resolved the issue …

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

You must be logged in to reply to this topic.