Repository navigation
2.0.0
A major release: Query now covers every query class of WordPress, and several arguments that were wrong or silently ignored are fixed. A few fixes change the results of a query that used to run, so read Upgrading before updating.
Added
- Query classes:
TermQuery(WP_Term_Query),UserQuery(WP_User_Query),CommentQuery(WP_Comment_Query),SiteQuery(WP_Site_Query) andNetworkQuery(WP_Network_Query). Every documented argument is covered. - Terminal methods, on every class:
first(),ids(),count()andexists(), which run on a copy of the builder and leave it untouched.TermQueryaddsnames()andslugs(),UserQueryaddspluck(). See Getting results. PostQueryarguments:pageId(),pagename(),title(),menuOrder(); the date fieldsyear(),month(),day(),hour(),minute(),second(),week()andyearMonth(); the top-level meta argumentsmetaKey(),metaValue(),metaCompare(),metaType(),metaCompareKey()andmetaTypeKey();orderByMeta();exactSearch(),searchSentence()andsearchColumns();noFoundRows(),suppressFilters()andlazyLoadTermMeta().- Meta clauses:
regexp(),notRegexp(),rlike(),keyCompare()andkeyType(). - Tax clauses:
containsAll()(operator => 'AND'). - Date clauses:
registered(), andinclusive()on a single clause. Query::tax(), next toQuery::meta()andQuery::date().- Documentation split into pages under
docs/, with a page per query class. Its examples are run by the test suite, and CI fails when one no longer matches the code.
Changed
where()followed byorWhere()is grouped like Eloquent.where(a)->where(b)->orWhere(c)is(a AND b) OR c; it used to turn the whole group intoa OR b OR c.DateQuery::inclusive()works. It was written where WordPress does not read it, so it had no effect; it is now written on each date clause.- Dates use a 24-hour clock. A date string was converted with the 12-hour format (
'2022-01-01'gavehour => 12,'… 15:10:00'gavehour => 3). The parts of a converted date are now integers. - Invalid values throw a
QueryExceptioninstead of being silently ignored:fields(),userPermission()and the direction oforderBy(). date()without a column no longer sends one, so WordPress uses the default of the queried table (post_date,user_registered,comment_date,registered).- Defaults chosen so that nothing is silently left out:
TermQueryreturns empty terms (hide_empty => false) andSiteQueryhas no cap of 100 sites (number => 0).PostQuerykeepspost_type => 'any'.CommentQuerykeeps WordPress' own defaults on purpose (no spam, no trash). See Concepts.
Fixed
DateQueryBuilder::within()always threw aTypeError.- A debug
var_exportprinted to the output when a date string was converted. - A numeric (timestamp) string given to
before()orafter()threw aTypeError. categoryAnd()sentcategory_and, which WordPress ignores; it now sendscategory__and.postType()did not accept an array.orderBy()with an array, andinRandomOrder()followed byorderBy()orlatest(), threw aTypeError.ofType()was ignored, and the type of a list was detected from its first value only (between(1, 50)wasBINARY,in([])raised a warning). One type now fits every value.- Calling
metaQuery(),taxQuery()ordateQuery()twice repeated the clauses of the first call.
Removed
- The public
initQuery(),query()andgenericQuery()methods of the query classes. They came from an internal trait by accident and were not documented.
Full changelog: 1.0.3...2.0.0