| @@ -75,9 +75,21 @@ | ||
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | foreach ($data['titles'] as $key => $value) { |
| 79 | - $existence = get_page_by_title($value, OBJECT, 'gvn_schart'); | |
| 79 | + $args = [ | |
| 80 | + 'post_type' => 'gvn_schart', | |
| 81 | + 'title' => $value, | |
| 82 | + 'post_status' => 'any', // Adjust if you only want published posts | |
| 83 | + 'numberposts' => 1, | |
| 84 | + ]; | |
| 85 | + | |
| 86 | + $query = new WP_Query($args); | |
| 87 | + $existence = $query->have_posts() ? $query->posts[0] : null; | |
| 88 | + | |
| 89 | + // Clean up after the query | |
| 90 | + wp_reset_postdata(); | |
| 91 | + | |
| 80 | 92 | |
| 81 | 93 | if (empty($existence)) { |
| 82 | 94 | $newid = wp_insert_post(array( |
| 83 | 95 | 'post_title' => $value, |