Debugging issue with custom post type publishing as blank

I’m adding another IF section for another custom post type to WP Discourse: advanced custom filter for discourse_publish_format_html … 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. 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?

1 Like

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…

1 Like

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.

1 Like

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

image

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 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.

2 Likes

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.

2 Likes