Error trapping for duplicate custom field rows? (2 posts)

  1. technabob
    Posted 2 years ago #

    I recently had a problem where my entire site blew up as it went into a nasty recursive loop because two rows were entered for a custom field on the site, when the code only expects one. Here the relevant excerpt my template code:

    $photoVar = post_custom('photo');
     $countVar = post_custom('count');
     for ($i = 2; $i <= $countVar; $i++) {
          echo "<a href='/photos/".$photoVar."_".$i.".jpg' class='thickbox' rel='$photoVar'></a>";}

    So basically, the problem was that due to data entry, we had two rows created for the "count" custom field, and all hell broke loose, with PHP using up all available memory in a second - especially with over 1000 simultaneous visitors.

    Is there a good way to trap for multiple post_custom rows? or is there a plugin that can prevent the creation of them in the first place? Or is there a simple way to handle this with PHP array handling that I'm not aware of?

  2. technabob
    Posted 2 years ago #

    Hmmm.... Does this make sense, or is there a tidier way to handle it?

    $countVar = post_custom('count');

Topic Closed

This topic has been closed to new replies.

About this Topic