Support » Themes and Templates » Error trapping for duplicate custom field rows?

  • 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?

Viewing 1 replies (of 1 total)
  • Hmmm…. Does this make sense, or is there a tidier way to handle it?

    $countVar = post_custom('count');
      if(is_array($countVar)){$countVar=$countVar[0];}
Viewing 1 replies (of 1 total)
  • The topic ‘Error trapping for duplicate custom field rows?’ is closed to new replies.