WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. technabob
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    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];}

Topic Closed

This topic has been closed to new replies.

About this Topic