Make WordPress Core

Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#40229 closed enhancement (fixed)

Add meta_query to wp_site_query

Reported by: spacedmonkey's profile spacedmonkey Owned by: flixos90's profile flixos90
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: ms-roadmap needs-patch has-dev-note
Focuses: multisite Cc:


Currently site query doesn't support meta query as there is no blogmeta table. However with it being added #37923 this functionally can be supported.

Along with adding support this functionality, we should start to use it in a number of place. A key example is adding the ability to search by site title in the network admin panel

Attachments (1)

40229.diff (15.3 KB) - added by flixos90 6 years ago.

Download all attachments as: .zip

Change History (21)

#1 @flixos90
7 years ago

  • Version 4.5 deleted

I suggest continuing with the site meta query functionality in #37923 for now, as we would like to work on the entire site meta feature in the format of a feature project (hosted at

When we get to committing, it probably makes sense to break things down to smaller parts, and then this sub-ticket here can come in handy. For now let's keep the discussion going in a centralized location (#37923).

This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.

7 years ago

#3 @spacedmonkey
7 years ago

  • Keywords needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to 4.9
  • Owner set to spacedmonkey
  • Status changed from new to assigned

#4 @flixos90
7 years ago

  • Keywords ms-roadmap added

These tickets belong to our planned roadmap (a few of them not per final decision), so flagging with a keyword for better overview.

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.

7 years ago

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.

7 years ago

#7 @flixos90
7 years ago

  • Keywords early added
  • Milestone changed from 4.9 to Future Release

#8 @flixos90
7 years ago

  • Keywords early removed
  • Milestone changed from Future Release to 5.0

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.

6 years ago

6 years ago

#10 @flixos90
6 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
  • Owner changed from spacedmonkey to flixos90

40229.diff implements meta query functionality in WP_Site_Query:

  • The implementation itself is trivial and straightforward. It follows mostly how other query classes do it. The orderby-meta functionality deserves an extra look because it's the most complicated part, but the provided tests confirm it works as expected.
  • class-wp-meta-query.php is loaded earlier in wp-settings.php to allow this functionality early during the multisite bootstrap process. This will fix #40948.
  • Comprehensive tests have been added for the meta query functionality, i.e. one parameterized test with 10 datasets, each testing different behavior.
  • Three additional tests have been added to verify that adding/updating/deleting site meta busts the site query cache.

#11 @flixos90
6 years ago

In 43009:

Bootstrap: Load class-wp-meta-query.php earlier in wp-settings.php.

This change is necessary to enable multisite-specific meta query functionality during the multisite bootstrap process.

Fixes #40948. See #40229.

#12 @flixos90
6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 43010:

Multisite: Add meta query functionality to WP_Site_Query.

After the introduction of site metadata in [42836], it should be possible to query sites by that data.

Fixes #40229.

#13 @flixos90
6 years ago

  • Keywords needs-dev-note added

#14 @spacedmonkey
6 years ago

@flixos90 I believe you need to put some clean_blog_cache / wp_cache_set( 'last_changed', microtime(), 'sites' ); calls into add_site_meta, update_site_meta and delete_site_meta.

Otherwise meta queries will not be invalidated.

#15 @flixos90
6 years ago

@spacedmonkey This is already in place via #37923.

#16 @flixos90
6 years ago

  • Milestone changed from 5.0 to 5.1
  • Resolution fixed deleted
  • Status changed from closed to reopened

Version numbers need to be adjusted to 5.1.0.

#17 @pento
5 years ago

  • Keywords needs-patch added; has-patch has-unit-tests removed

#18 @flixos90
5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 44467:

Multisite: Update @since tags for site meta introduction.

Fixes #37923. Fixes #40229.

#19 @flixos90
5 years ago

  • Keywords needs-dev-note removed
Note: See TracTickets for help on using tickets.