0, 'terms' => 0, 'redirects' => 0, 'settings' => false ); if ( ! post_type_exists( 'product' ) ) { return $counts; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $counts['posts'] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM %i WHERE post_type = 'product' AND post_status = 'publish'", $wpdb->posts ) ); return $counts; } public function post_ids( int $after, int $limit ): array { global $wpdb; if ( ! post_type_exists( 'product' ) ) { return array(); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product' AND post_status = 'publish' AND ID > %d ORDER BY ID ASC LIMIT %d", $after, max( 1, $limit ) ) ); return array_map( 'intval', (array) $ids ); } public function post_record( int $post_id ): array { $post = get_post( $post_id ); if ( ! $post instanceof \WP_Post || 'product' !== $post->post_type ) { return array(); } $short = trim( wp_strip_all_tags( (string) $post->post_excerpt ) ); $record = array( 'desc' => '' !== $short ? mb_substr( $short, 0, 300 ) : '', 'schema_type' => 'Product', ); // A product hidden from the catalogue and from search is not a page // anyone should land on from Google. $visibility = wp_get_object_terms( $post_id, 'product_visibility', array( 'fields' => 'slugs' ) ); if ( is_array( $visibility ) && in_array( 'exclude-from-search', $visibility, true ) && in_array( 'exclude-from-catalog', $visibility, true ) ) { $record['robots'] = array( 'noindex' ); $record['exclude_sitemap'] = true; } return $this->clean( $record ); } }