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

Post status is always private when fetching posts in the block editor API #74

Open
bonny opened this issue Jan 13, 2023 · 3 comments
Open

Comments

@bonny
Copy link
Contributor

bonny commented Jan 13, 2023

I have a Gutenberg Block that fetches posts from a custom post type.
The custom post type does have a custom status registered.

The code in the block look something like this:

const POST_TYPE = 'my-custom-post-type';

// Get custom post type pages.
const childPages = useSelect((select) =>
  select('core').getEntityRecords('postType', POST_TYPE)
);

// childPages will look like this
// (only relevant keys kept)
// "status" is always "private"
// and we need to check "custom_status"
// to get the real status of the post.
[
  {
    "id": 123,
    "type": "my-custom-post-type",
    "status": "private",
    "custom_status": "publish"
  },
  {
	  // ...second post and so on
  },
]

I see that a check is in place to

Always trick the Block Editor so that is uses the "Update" major action button.

But it seems like this check also is true when getting pages from a block because the referer value seems to be the same as for the edit post api call.

I have solved this by checking if custom_status exists and use that value with a fallback to status, but I guess this would be a problem for other third party blocks that does not have this check.

@huubl
Copy link

huubl commented Mar 15, 2024

Same here, did you find a solution?

@imath
Copy link
Owner

imath commented Mar 15, 2024

Unless there's now a hook provided by WordPress to replace the component to save posts, there's no other means to use a custom status within the Block Editor. If you find one, be my guest and submit a pull request :)

@huubl
Copy link

huubl commented Mar 20, 2024

Hmm, that's unfortunate. Hopefully the Block Editor will support custom post statuses anytime soon. However, based on this issue, which is almost as old as Gutenberg itself, it doesn't seem to have any priority.

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

No branches or pull requests

3 participants