'page', 'title' => 'Contact', 'fields' => 'ids' )); if ($contact->have_posts()) { $ID = $contact->posts[0]; $out['contact'] = array( 'title' => 'Contact', 'id' => $ID, 'url' => get_the_permalink($ID), ); } wp_reset_postdata(); $more = new WP_Query(array( 'post_type' => 'page', 'post_parent' => $out['contact'], 'posts_per_page' => -1 )); if ($more->have_posts()) { while ($more->have_posts()) { $more->the_post(); $title = get_the_title(); $out[sanitize_title($title)] = array( 'title' => $title, 'id' => get_the_ID(), 'url' => get_the_permalink(), ); } } wp_reset_postdata(); update_option('jvbContactPage', $out); } if (array_key_exists($page, $out)) { return $out[$page][$field]; } return $out['contact']['url']; } /** * @return int|false */ function jvbAboutPage():int|false { $out = get_option('jvbAboutPage'); if (!$out) { $about = new WP_Query(array( 'post_type' => 'page', 'title' => 'About', 'fields' => 'ids' )); if ($about->have_posts()) { $out = $about->posts[0]; } } return $out; } function jvbGetPageId(string $title):int { $page = new WP_Query( [ 'post_type' => 'page', 'title' => $title, 'posts_per_page' => 1, 'fields' => 'ids', ] ); wp_reset_postdata(); $result = ($page->have_posts()) ? $page->posts[0] : false; if (!$result) { $result = wp_insert_post([ 'post_title' => $title, 'post_type' => 'page', 'post_status' => 'publish', ]); } return $result; }