Skip to content

fix: honor selected post_types on the Posts generate endpoint#210

Merged
bordoni merged 1 commit into
mainfrom
fix/post-types-not-honored-from-form
May 22, 2026
Merged

fix: honor selected post_types on the Posts generate endpoint#210
bordoni merged 1 commit into
mainfrom
fix/post-types-not-honored-from-form

Conversation

@bordoni
Copy link
Copy Markdown
Owner

@bordoni bordoni commented May 22, 2026

Summary

  • Declares post_types (plural) as the canonical parameter on POST /fakerpress/v1/posts/generate, accepting either an array of slugs or a comma-separated string — matching what the admin form actually submits.
  • Keeps post_type (singular) as a documented alias for older REST consumers, but stops letting its schema default (post) silently overwrite an explicitly-supplied post_types value.
  • Adds four targeted regression tests covering the form serialization (CSV string), array payloads, multi-type sampling, and the precedence rule that pinned the bug.

Refs wp.org support thread: https://wordpress.org/support/topic/doesnt-seem-to-create-pages-now/

Why this slipped through

The endpoint's existing test only ever exercised post_type (singular) — the alias the schema knew about. The admin form serializes its post-type dropdown as post_types[]/post_types, so live users hit a code path no test covered. Because the schema also defaulted the singular alias to post, the translation block in the handler kept clobbering the plural value with that default, and every generation came out as a Post regardless of selection.

Test plan

  • slic run wpunit — 67 tests, 249 assertions, all green (4 new tests for this regression).
  • Manual: load `wp-admin/admin.php?page=fakerpress-posts`, deselect Post, select Page (optionally choose a parent), click Generate; confirm the generated items appear under `wp-admin/edit.php?post_type=page`.
  • composer lint:php against the changed file — no new violations introduced.

@bordoni bordoni added this to the 0.9.1 milestone May 22, 2026
The admin Posts form serializes the post-type selector as `post_types`
(plural) and POSTs straight to /fakerpress/v1/posts/generate. The schema
only declared the singular `post_type` (with a default of `post`), and the
handler unconditionally clobbered `post_types` with whatever was in
`post_type` — meaning the default `post` always won, even when the user
explicitly picked Pages. Reporters saw only Posts created no matter what
they selected.

The schema now exposes `post_types` as the canonical parameter (accepts
array or comma-separated string) while keeping `post_type` as a documented
singular alias for older REST clients. The translation prefers the plural
value when present and falls back to the alias only when it isn't, so the
admin form, the singular alias, and array-shaped JSON payloads all land at
the same module input.

Tests: PostsEndpointTest gains four regressions — plural CSV, plural array,
multi-type CSV, and an explicit "plural wins over singular default" check
that pins the exact bug.

Refs: https://wordpress.org/support/topic/doesnt-seem-to-create-pages-now/
@bordoni bordoni force-pushed the fix/post-types-not-honored-from-form branch from 5903a0d to 52f941f Compare May 22, 2026 18:10
@bordoni bordoni merged commit 39accf6 into main May 22, 2026
3 of 5 checks passed
bordoni added a commit that referenced this pull request May 22, 2026
Two wp.org regressions land in this patch release:

- #209 — `WP_Meta::meta_type_date` fataled with "Class 'Chronos' not
  found" because the provider file never imported Chronos. Restores
  date-type meta generation and adds a regression test path
  (WP_MetaTest plus an end-to-end REST repro).
- #210 — The Posts generator silently created Posts instead of the
  user-selected type because the admin form's plural `post_types` value
  was overwritten by the singular alias's default of `post`. The schema
  now documents `post_types` as the canonical parameter (array or CSV)
  with `post_type` kept as a deprecated alias.

Plus a PHP 8.x undefined-property warning in `WP_Post::tax_input` and
fresh wpunit coverage that pins both regressions in place.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant