Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the format property in query #7314

Open
wants to merge 18 commits into
base: trunk
Choose a base branch
from

Commits on Sep 9, 2024

  1. Add support for the format property in query

    Adds handling the format property ($request['format'] ) in the class WP_REST_Posts_Controller.
    
    Adds handling the format property ($block->context['query']['format'])  in the function build_query_vars_from_query_block.
    carolinan committed Sep 9, 2024
    Configuration menu
    Copy the full SHA
    7b34ec9 View commit details
    Browse the repository at this point in the history
  2. Tests: Add format as a valid parameter in WP_Test_REST_Posts_Controll…

    …er::test_registered_query_params
    carolinan committed Sep 9, 2024
    Configuration menu
    Copy the full SHA
    24efb21 View commit details
    Browse the repository at this point in the history

Commits on Sep 11, 2024

  1. build_query_vars_from_query_block: Fix incorrect variable name and br…

    …oken logic
    
    In `build_query_vars_from_query_block`, the variable that contains the format attribute had the wrong name, which caused a PHP warning. The variable name was updated to `$formats`.
    
    One of the if-statements was closed incorrectly, which meant that all the logic for handling the format property was not used. Because of this, the wrong posts showed in the query loop block on the front of the site.
    The closing curly bracket for the if-statement was moved to solve this.
    
    One additional check was added to the wrapping if-statement:
    It now checks that `$block->context['query']['format']` is not empty, and is an array, before running the rest of the code.
    carolinan committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    8e44597 View commit details
    Browse the repository at this point in the history
  2. Tests: Update the qunit fixture in wp-api-generated.js

    Generated an updated fixture in `wp-api-generated.js` by running the PHPUnit tests.
    The update adds `format` to `mockedApiResponse.Schema`
    carolinan committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    d7ab338 View commit details
    Browse the repository at this point in the history
  3. WP_REST_Posts_Controller: remove redundant array conversion for the…

    … post formats.
    
    `WP_REST_Posts_Controller`: remove unnecessary array conversion for the `format` parameter.
    This addresses feedback that was left on the Gutenberg pull request.
    carolinan committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    a4fb1b4 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7eec23a View commit details
    Browse the repository at this point in the history
  5. WP_REST_Posts_Controller get_collection_params: add uniqueItems

    … to `$query_params['format']`
    
    In `WP_REST_Posts_Controller` `get_collection_params` class method; add `uniqueItems` to the `$query_params['format']` array.
    
    The purpose is to require all items in the array to be unique.
    This will help manage user errors, if duplicate items are passed in the `format` parameter.
    
    This change addresses feedback left on the Gutenberg pull request.
    carolinan committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    83eefcb View commit details
    Browse the repository at this point in the history
  6. Tests: Update the qunit fixtures in wp-api-generated.js

    Adds the regenerated fixtures which includes `uniqueItems` in the `format` array in `mockedApiResponse.Schema`.
    
    The fixture was regenerated by running the PHPUNit tests.
    carolinan committed Sep 11, 2024
    Configuration menu
    Copy the full SHA
    5fb2c49 View commit details
    Browse the repository at this point in the history

Commits on Sep 12, 2024

  1. Update the format of inline comments

    Use multiline comments instead of multiple single line comments.
    carolinan committed Sep 12, 2024
    Configuration menu
    Copy the full SHA
    5058604 View commit details
    Browse the repository at this point in the history

Commits on Sep 17, 2024

  1. Remove unnecessary terms from the query for the standard format

    In the `build_query_vars_from_query_block` function and the `WP_REST_Posts_Controller` class, a query with the `NOT EXISTS` operator is used to exclude all items that have a post format assigned.
    
    This commit removes a `terms` parameter from the two queries, because the terms are redundant when `NOT EXISTS` is used.
    carolinan committed Sep 17, 2024
    Configuration menu
    Copy the full SHA
    1b974aa View commit details
    Browse the repository at this point in the history
  2. Change the relation from OR to AND when querying for the format

    When querying for the `format` property in the `build_query_vars_from_query_block` function and the `WP_REST_Posts_Controller` class, the query may be combined with other taxonomy queries. For example, the user may expect the result to be posts with a specific format and a specific category.
    
    Previously, the `relation` parameter in the query was set to `OR`, which should return items that has either the format or the taxonomy.
    
    This commit changes the `relation` to `AND` with the intention to limit the result to items that have both the queried taxonomy and the format.
    carolinan committed Sep 17, 2024
    Configuration menu
    Copy the full SHA
    3244361 View commit details
    Browse the repository at this point in the history
  3. In build_query_vars_from_query_block: validate the formats

    Validate the that the `format` property passed to the query using the block context is either the default (standard) or a supported post format, registered with `add_theme_support()`.
    
    Compare `format` to the supported formats in  `get_post_format_slugs()` and remove invalid formats.
    carolinan committed Sep 17, 2024
    Configuration menu
    Copy the full SHA
    5ee2750 View commit details
    Browse the repository at this point in the history

Commits on Sep 19, 2024

  1. WP_REST_Posts_Controller: Change the relation from AND to OR wh…

    …en querying for the `format`
    
    When querying for the `format` property in the `WP_REST_Posts_Controller` class,  the `relation` parameter in the query was incorrectly set to `AND`.
    This commit changes the relation back to `OR`.
    
    This is needed because when a user queries for a combination of the `standard` post format and any other format, the result should include items with either the given format, or no format (standard).
    A post item can not have more than one format.
    
    The commit also renames the variable `$tax_query` to `$formats_query` to improve the readability.
    carolinan committed Sep 19, 2024
    Configuration menu
    Copy the full SHA
    c71f92f View commit details
    Browse the repository at this point in the history
  2. build_query_vars_from_query_block: Change the relation when queryin…

    …g for the `format`
    
    When querying for the `format` property in `build_query_vars_from_query_block`, the `relation` parameter in the query was incorrectly set to `AND`.
    This commit changes the relation back to `OR`.
    
    This is needed because when a user queries for a combination of the `standard` post format and any other format, the result should include items with either the given format, or no format (standard).
    A post item can not have more than one format.
    
    The commit also renames the variable `$tax_query` to `$formats_query` to improve the readability.
    carolinan committed Sep 19, 2024
    Configuration menu
    Copy the full SHA
    19ba793 View commit details
    Browse the repository at this point in the history
  3. Formats: address feedback from code review and PHPCS issues

    This commit corrects inline docBlocks, removes unnecessary string concatenations, and tries to resolve a PHP coding standard issue about the formatting of an array.
    carolinan committed Sep 19, 2024
    Configuration menu
    Copy the full SHA
    ef44367 View commit details
    Browse the repository at this point in the history
  4. build_query_vars_from_query_block: Try to resolve the nested relations

    When querying for formats, the relation between the format and other taxonomies like categoryíes and tags should be `AND`.
    
    The intention is to allow users to query for a post with a specific category and a specific format.
    carolinan committed Sep 19, 2024
    Configuration menu
    Copy the full SHA
    47e1581 View commit details
    Browse the repository at this point in the history

Commits on Sep 20, 2024

  1. Configuration menu
    Copy the full SHA
    ad5ea9f View commit details
    Browse the repository at this point in the history

Commits on Sep 23, 2024

  1. Configuration menu
    Copy the full SHA
    0d3d4dc View commit details
    Browse the repository at this point in the history