Aloha, gentlemen coders. I’m never a programmer at all, but I’m trying hard to figure out why this code is:

if (!isset($location_result->post_parent )) { $locations_select .= '<option value="' . esc_attr($location_result->ID) . '" ' . ($location_result->ID == $l ? 'selected' : '') . '>' . $location_result->post_title . '</option>'; } else { $locations_select .= '<option value="' . esc_attr($location_result->ID) . '" ' . ($location_result->ID == $l ? 'selected' : '') . '>&nbsp;&nbsp;&nbsp;' . $location_result->post_title . '</option>'; } 

It causes all elements of the list to move in general, even those that do not have a parent page. Question on WordPress, respectively.

    1 answer 1

    Because the post_parent field of the post object is always present. So, isset always returns true. The first line should look like this:

     if ($location_result->post_parent == 0) { 

    because for those pages / posts that don't have parents, post_parent is 0.