Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP PHP/WP problem with code, trouble accessing custom archive links

wyclef

Active Coder
Hello, I have an old custom WP site that was working fine running PHP 7.3.9 and WP 4.9.18 and since upgrading to PHP 7.4.21 and WP 5.6.10 the archive links by year to access older data are no longer doing anything other than reloading the same page. I was wondering if someone might be able to take a look and see if they see anything obvious that could be causing the issue on the PHP side? I added a few comments of some errors WP was logging but they seem fairly inconsequential in regard to this problem but maybe there is something there. Thanks!

PHP:
<!-- Was working PHP 7.3.9, WP 4.9.18
     Not working PHP 7.4.21, WP 5.6.10 -->
     <div>
  <h3>Newsletter</h3>
  <ul>
    <?php $urlSplits = explode('/', $_SERVER['REQUEST_URI']); ?>
    <?php $counter = 0; ?>
    <?php
      while(the_repeater_field('external-links')):
        $tempDate = explode(',', get_sub_field('date'));
        $mediaYears[] = $tempDate['1'];                   // *** Notice: Undefined offset: 1
        $data[$counter]['year'] = $tempDate['1'];         // *** Notice: Undefined offset: 1
        $data[$counter]['date'] = get_sub_field('date');
        $data[$counter]['link'] = get_sub_field('link');
        $data[$counter]['title'] = get_sub_field('title');
        $counter++;
      endwhile;
    ?>
    <?php
      $keys = 0;
      $mediaYears = array_unique($mediaYears);
      foreach ($mediaYears as $value) {
        if ($value != '') {
          $uniqueYears[$keys] = $value;
          $keys++;
        }
      }
      rsort($uniqueYears);
      $data = array_reverse($data, true);
      if ($urlSplits[3] != '') {
        $currentYear = str_replace(' ', '', $urlSplits[3]);
      } else {
        $currentYear = str_replace(' ', '', $uniqueYears[0]);
      }
    ?>
    <?php for($i = count($data); $i >= 0; $i--) { ?>
      <?php if ($currentYear == $data[$i]['year']) {
        // *** Notice: Undefined offset: 135
        // *** Notice: Trying to access array offset on value of type null
      ?>
      <li>
        <em><?php echo $data[$i]['date'] ?></em>
        <strong><a href="<?php  echo $data[$i]['link'] ?>" rel="bookmark"><?php  echo $data[$i]['title'] ?></a></strong>
      </li>
      <?php } ?>
    <?php } ?>
  </ul>
  <?php for ($i = 0; $i < count($uniqueYears); $i++) { ?>
    <!-- THIS IS THE LINE THAT CREATES THE YEAR LINKS TO GO TO ARCHIVE PAGES -->
    <a href="https://www.domain.org/news/newsletter/<?php  echo str_replace(' ', '', $uniqueYears[$i]); ?>"><?php  echo $uniqueYears[$i]; ?></a>
    <!-- Permalink set to Custom Structure: /news/%category%/%year%/%monthnum%/%postname%/ (Not sure if this is relevant) -->
  <?php } ?>
</div>
 
Why do you believe these errors about undefined offsets are 'fairly inconsequential' ? They look pretty serious to me. I would assume they will likely cause the ensuing code to malfunction.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom