# Debugging issue with custom post type publishing as blank

**URL:** https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750
**Category:** WordPress
**Created:** [July 14, 2020, 9:06pm UTC](https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750 "2020-07-14T21:06:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 14, 2020, 9:06pm UTC](https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750/1 "2020-07-14T21:06:00Z")

</div>

I’m adding another IF section for another custom post type to [WP Discourse: advanced custom filter for discourse\_publish\_format\_html - #12 by Kayla](https://meta.discourse.org/t/wp-discourse-advanced-custom-filter-for-discourse-publish-format-html/106059/12) … this is the same post type I wanted to restrict to a specific Discourse topic and automatically publish per my recent topic [Filtering the available categories for a custom post type](https://meta.discourse.org/t/filtering-the-available-categories-for-a-custom-post-type/157298). The posts are automatically publishing to the correct topic, but the custom fields I’m attempted to include in the discourse\_publish\_format\_html are coming over as empty. I’ve quadrupled checked all my field names and still everything but the field values themselves seem to be coming over to Discourse.

Curious if any of these factors could be the reason?

1. CPT is created in Wordpress via Gravity Forms Advanced Post Creation Add-On plugin
2. CPT has Toolset Access applied so only editors can see these particular posts; WP status is published
3. CPT is being published to a private Discourse category

The bits that do come over to Discourse is post/topic title, {author} and {blogurl}. Perhaps the key is that {excerpt} also returns blank along with the custom fields?

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 14, 2020, 10:57pm UTC](https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750/2 "2020-07-14T22:57:11Z")

</div>

Update: completely disabling Toolset Access and/or creating a post via Wordpress instead of the Gravity Form did not fix the blank custom fields. {excerpt} did start coming through, on the other hand…

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 14, 2020, 11:19pm UTC](https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750/3 "2020-07-14T23:19:53Z")

</div>

To clarify, Toolset Access does not seem to have a bearing on this difference with {excerpt}.

If I create a post via the WP admin, {excerpt} comes through (post is using blocks editor). {excerpt} publishes as blank if created through the Gravity Form (which creates a “classic” block to hold the WYSIWYG field).

Custom fields (single line, multi-line and number) still returning blank no matter how the post is created.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [July 15, 2020, 12:30am UTC](https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750/4 "2020-07-15T00:30:53Z")

</div>

> [@Kayla](#):
>
> The posts are automatically publishing to the correct topic, but the custom fields I’m attempted to include in the discourse\_publish\_format\_html are coming over as empty

After you publish the post, are you seeing a notice similar to this in the editor’s Discourse sidebar?

 ![image](https://global.discourse-cdn.com/meta/original/3X/7/9/79f5e53937998c7d7e564e0dc6834f5bf7c29fac.png)

If the ‘success’ message is not displayed, but the post has been published, then the issue is with the custom post type’s configuration.

If the ‘success’ message is being displayed, the custom fields should be available as post metadata that can be returned with `get_post_meta( $post_id, 'your_meta_key_name', true );`. The easiest way to figure out what is going on would be to write to a [`debug.log`](https://wordpress.org/support/article/debugging-in-wordpress/#wp_debug_log) file from your `cosmos_custom_publish_format_html` function.

I’m away from work for the week, so I might be slower at answering questions than I normally am.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [July 15, 2020, 6:04am UTC](https://meta.discourse.org/t/debugging-issue-with-custom-post-type-publishing-as-blank/157750/5 "2020-07-15T06:04:04Z")

</div>

I’ve finally narrowed it down: the issue seems to come from the automatic publishing option (also a new factor, overlooked). If I uncheck this, publish the post on Wordpress, _then_ publish to Discourse, the custom fields come over to Discourse and display as they should. Or if I allow the auto-publishing to happen, the fields will show up in Discourse after hitting Update Discourse Topic in Wordpress. So it seems that when the post is automatically published, it publishes before the data in the custom fields is properly saved in Wordpress.
