‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 5, ‘s’ => sanitize_text_field($tag) ]); foreach ($results as $post) { if (!in_array($post->ID, $unique_ids)) { $posts[] = $post; $unique_ids[] = $post->ID; } } } } // Priority 2: Focus Keyword if ( empty($posts) && !empty($generated['focus_keyword']) ) { $results = get_posts([ 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 5, 's' => sanitize_text_field( $generated['focus_keyword'] ) ]); foreach ($results as $post) { if (!in_array($post->ID, $unique_ids)) { $posts[] = $post; $unique_ids[] = $post->ID; } } } // Priority 3: Latest Articles if (empty($posts)) { $posts = get_posts([ 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ]); } return array_slice($posts, 0, 5); } /** • Append Related Articles section • to generated article content. */ function stai_insert_internal_links( $article, $generated ) { $links = stai_get_internal_links( $generated ); if (empty($links)) { return $article; } $html = “”; $html .= ’ Related Articles ‘; $html .=’ ’; foreach ($links as $post) { if (empty($post->ID)) { continue; } $html .= sprintf( '