Debugging issue with custom post type publishing as blank
User Kayla is experiencing issues with custom fields not being published to Discourse when using a custom post type (CPT) created via Gravity Forms Advanced Post Creation Add-On plugin. Despite quadruple-checking field names, only the post/topic title, author, and blog URL are being published, while custom fields and excerpt return blank.
Kayla discovered that disabling Toolset Access and creating a post via WordPress instead of Gravity Forms did not resolve the issue, but did cause the excerpt to start coming through.
Kayla eventually narrowed down the issue to the automatic publishing option, which causes the post to publish before the custom field data is properly saved in WordPress. Unchecking this option and publishing the post manually, or allowing auto-publishing and then hitting “Update Discourse Topic” in WordPress, resolves the issue.
Simon suggested checking the Discourse sidebar for a success message and writing to a debug.log file from the cosmos_custom_publish_format_html function to further investigate the issue.
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 … 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?
CPT is created in Wordpress via Gravity Forms Advanced Post Creation Add-On plugin
CPT has Toolset Access applied so only editors can see these particular posts; WP status is published
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?
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…
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.
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.
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.