WP_Site_Query::get_site_ids(): int|array
- Since
- 4.6.0
- Source
wp-includes/class-wp-site-query.php:440
Compatibility
- WordPress
- since 4.6.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
int|array- A single count of site IDs if a count query. An array of site IDs if a full query.
Performance profile
How much work a call to WP_Site_Query::get_site_ids() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Constant
- Instructions
- 237–251
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches the database via ->get_var().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 660.
Third-party callbacks on 'site_search_columns', 'sites_clauses' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - sqldatabase query
->get_var()called directly
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Query::get_site_ids() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($value) && empty($number) && empty($site_id) && empty($network_id) && empty($date_query) && !$clauses | 237–247 | ->parse_order(), absint(), absint(), absint(), absint(), compact(), ->get_var() |
empty($value) && empty($number) && empty($site_id) && empty($network_id) && empty($date_query) && !$clauses | 241–251 | ->parse_order(), absint(), absint(), absint(), absint(), compact(), ->get_col(), array_map() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 659 | 237–251 | 51 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 660 | 237–251 | 51 | |
| 8.4 | 660 | 237–251 | 51 | 57 fewer instructions than PHP 8.3 |
| 8.3 | 717 | 255–269 | 51 | |
| 8.2 | 717 | 255–269 | 51 | |
| 8.1 | 717 | 255–269 | 51 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 718 | 255–269 | 51 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while WP_Site_Query::get_site_ids() runs, in this order:
- apply_filters( site_search_columns )filterline 627 (+187 into the body)
Filters the columns to search in a WP_Site_Query search.
Uses · 8
- absint()Converts a value to non-negative integer.
- wp_parse_id_list()Cleans up an array, comma- or space-separated list of IDs.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- apply_filters_ref_array()Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
- WP_Site_Query::parse_order()Parses an 'order' query variable and cast it to 'ASC' or 'DESC' as necessary.
- WP_Site_Query::parse_orderby()Parses and sanitizes 'orderby' keys passed to the site query.
- WP_Site_Query::get_search_sql()Used internally to generate an SQL string for searching across multiple columns.
- WP_Date_Query::__construct()Constructor.
Used by · 1
- WP_Site_Query::get_sites()Retrieves a list of sites matching the query vars.
Source code
protected function get_site_ids() { global $wpdb; $order = $this->parse_order( $this->query_vars['order'] ); // Disable ORDER BY with 'none', an empty array, or boolean false. if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) { $orderby = ''; } elseif ( ! empty( $this->query_vars['orderby'] ) ) { $ordersby = is_array( $this->query_vars['orderby'] ) ? $this->query_vars['orderby'] : preg_split( '/[,\s]/', $this->query_vars['orderby'] ); $orderby_array = array(); foreach ( $ordersby as $_key => $_value ) { if ( ! $_value ) { continue; } if ( is_int( $_key ) ) { $_orderby = $_value; $_order = $order; } else { $_orderby = $_key; $_order = $_value; } $parsed = $this->parse_orderby( $_orderby ); if ( ! $parsed ) { continue; } if ( 'site__in' === $_orderby || 'network__in' === $_orderby ) { $orderby_array[] = $parsed; continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); } $orderby = implode( ', ', $orderby_array ); } else { $orderby = "{$wpdb->blogs}.blog_id $order"; } $number = absint( $this->query_vars['number'] ); $offset = absint( $this->query_vars['offset'] ); $limits = ''; if ( ! empty( $number ) ) { if ( $offset ) { $limits = 'LIMIT ' . $offset . ',' . $number; } else { $limits = 'LIMIT ' . $number; } } if ( $this->query_vars['count'] ) { $fields = 'COUNT(*)'; } else { $fields = "{$wpdb->blogs}.blog_id"; } // Parse site IDs for an IN clause. $site_id = absint( $this->query_vars['ID'] ); if ( ! empty( $site_id ) ) { $this->sql_clauses['where']['ID'] = $wpdb->prepare( "{$wpdb->blogs}.blog_id = %d", $site_id ); } // Parse site IDs for an IN clause. if ( ! empty( $this->query_vars['site__in'] ) ) { $this->sql_clauses['where']['site__in'] = "{$wpdb->blogs}.blog_id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__in'] ) ) . ' )'; } // Parse site IDs for a NOT IN clause. if ( ! empty( $this->query_vars['site__not_in'] ) ) { $this->sql_clauses['where']['site__not_in'] = "{$wpdb->blogs}.blog_id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['site__not_in'] ) ) . ' )'; }Changelog
Introduced in 4.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-site-query.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.