0 && 'publish' === get_post_status( $id ) ) { $pages[] = $id; } } } $privacy = (int) get_option( 'wp_page_for_privacy_policy' ); if ( $privacy && 'publish' === get_post_status( $privacy ) ) { $pages[] = $privacy; } foreach ( self::find_policy_pages() as $id ) { $pages[] = $id; } $pages = array_unique( $pages ); if ( $pages ) { $out .= "## Store information\n\n"; foreach ( $pages as $id ) { $out .= '- [' . wp_strip_all_tags( get_the_title( $id ) ) . '](' . get_permalink( $id ) . ")\n"; } $out .= "\n"; } $cats = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => true, 'number' => 30, 'orderby' => 'count', 'order' => 'DESC', ) ); if ( ! is_wp_error( $cats ) && $cats ) { $out .= "## Product categories\n\n"; foreach ( $cats as $cat ) { $line = '- [' . wp_strip_all_tags( $cat->name ) . '](' . get_term_link( $cat ) . ')'; if ( $cat->description ) { $line .= ': ' . wp_trim_words( wp_strip_all_tags( $cat->description ), 20 ); } $out .= $line . "\n"; } $out .= "\n"; } if ( function_exists( 'wc_get_products' ) ) { $products = wc_get_products( array( 'status' => 'publish', 'limit' => 20, 'orderby' => 'popularity', ) ); if ( $products ) { $out .= "## Popular products\n\n"; foreach ( $products as $product ) { $out .= '- [' . wp_strip_all_tags( $product->get_name() ) . '](' . $product->get_permalink() . ")\n"; } $out .= "\n"; } } /** * Filter the generated llms.txt content. * * @param string $out Content. */ return (string) apply_filters( 'agentaisle_llms_generated', $out ); } /** * Find published shipping, returns and contact pages by title. * * @return int[] */ private static function find_policy_pages() { $ids = array(); foreach ( array( 'shipping', 'delivery', 'return', 'refund', 'contact', 'about' ) as $term ) { $found = get_posts( array( 'post_type' => 'page', 'post_status' => 'publish', 's' => $term, 'search_columns' => array( 'post_title' ), 'posts_per_page' => 1, 'fields' => 'ids', ) ); $ids = array_merge( $ids, $found ); } return $ids; } }