query_vars['fulgid_aicogu_query'])) { return $posts; } // Remove this filter to avoid infinite loops remove_filter('the_posts', array($this, 'filter_noindex_posts'), 10); if (empty($posts)) { return $posts; } $filtered_posts = array(); foreach ($posts as $post) { // Skip posts with noindex directive if ($this->is_post_noindex($post->ID)) { continue; } $filtered_posts[] = $post; } return $filtered_posts; } /** * Get posts for a specific post type, with noindex filtering. * * @param string $post_type The post type. * @param int $limit Maximum number of posts to return. * @return array Array of post objects. */ public function get_posts_for_llms_txt($post_type, $limit = 20) { $args = array( 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => $limit, 'orderby' => 'date', 'order' => 'DESC', 'fulgid_aicogu_query' => true, // Custom flag to identify our queries ); $posts = get_posts($args); return $posts; } /** * Get focus keywords from SEO plugins. * * @param int $post_id The post ID. * @return array Array of focus keywords. */ public function get_focus_keywords($post_id) { $keywords = array(); // Check Yoast SEO if (defined('WPSEO_VERSION')) { $focus_kw = get_post_meta($post_id, '_yoast_wpseo_focuskw', true); if (!empty($focus_kw)) { $keywords[] = $focus_kw; } // Check for Yoast SEO Premium additional keywords $focus_kw_additional = get_post_meta($post_id, '_yoast_wpseo_focuskeywords', true); if (!empty($focus_kw_additional) && is_array(json_decode($focus_kw_additional, true))) { $additional_kws = json_decode($focus_kw_additional, true); foreach ($additional_kws as $kw_data) { if (isset($kw_data['keyword'])) { $keywords[] = $kw_data['keyword']; } } } } // Check Rank Math if (class_exists('RankMath')) { $focus_kw = get_post_meta($post_id, 'rank_math_focus_keyword', true); if (!empty($focus_kw)) { $kw_array = explode(',', $focus_kw); $keywords = array_merge($keywords, array_map('trim', $kw_array)); } } // Return unique keywords return array_unique(array_filter($keywords)); } /** * Add SEO keywords to the llms.txt file content. * * @param string $content Current content. * @param int $post_id Post ID. * @return string Modified content with keywords. */ public function add_keywords_to_content($content, $post_id) { $keywords = $this->get_focus_keywords($post_id); if (!empty($keywords)) { $content .= " Keywords: " . implode(', ', $keywords); } return $content; } }