P
P
Petr Volkhanov2018-05-05 14:57:55
WordPress
Petr Volkhanov, 2018-05-05 14:57:55

Why does this piece of code result in a 500 error on the site?

Why does this piece of code result in a 500 error on the site?

add_shortcode('in', 'in');
function in(){
  global $post;
  if(get_post_meta($post->ID, 'work')){
    $work = get_post_meta($post->ID, 'work');
    foreach ($work as $options) {
      foreach ($options as $key) {
        if ($key == "in") {
          $hour = get_post_meta($post->ID, 'app_price_1hour');
          $2hour = get_post_meta($post->ID, 'app_price_2hour');
          $night = get_post_meta($post->ID, 'app_price_night');
          $output = "<h4>Апартаменты</h4><p><b>Цена за час:</b> &#8362;".$hour[0]."</p><p><b>Цена за 2 часа:</b> &#8362;".$2hour[0]."</p><p><b>Цена за ночь:</b> &#8362;".$night[0]."</p>";
          return $output;
        }
      }
    }
    unset($work, $options, $key, $output, $hour, $2hour, $night);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Merzley, 2018-05-05
@eprivalov

In PHP, a variable name cannot start with a number. Rename the $2hour variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question