*/ public function published( int $limit = 3 ): array { $pages = array(); foreach ( array_slice( $this->ids(), 0, max( 1, min( 10, $limit ) ) ) as $id ) { $url = get_permalink( $id ); if ( ! $url ) { continue; } $pages[] = array( 'id' => $id, 'title' => get_the_title( $id ), 'url' => $url, ); } return $pages; } /** * Up to ten matching post ids, newest first. * * @return int[] */ private function ids(): array { $cached = get_transient( self::CACHE ); if ( is_array( $cached ) ) { return array_map( 'intval', $cached ); } global $wpdb; $types = array_values( get_post_types( array( 'public' => true ) ) ); if ( ! $types ) { return array(); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Content search WP_Query cannot express; the result is cached in a transient cleared on post changes. $ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_password = '' AND ( post_content LIKE %s OR post_content LIKE %s ) AND post_type IN (" . implode( ',', array_fill( 0, count( $types ), '%s' ) ) . ') ORDER BY post_modified_gmt DESC LIMIT 10', array_merge( array( '%' . $wpdb->esc_like( '[abientot_booking_form' ) . '%', '%' . $wpdb->esc_like( '