I’ve searched around and am not seeing anything specific about this. I can successfully grab and display custom fields when posting to Discourse from Wordpress as part of the topic “content” and create different templates according to post type, but is it possible to use a custom field to rewrite the Discourse topic title? Such as appending a formatted date field to an “event” title when it gets posted to Discourse?
AI-generated summary
Discourse_publish_format_html → rewrite topic title?
Kayla is trying to use a custom field to rewrite the Discourse topic title, specifically appending a formatted date field to an “event” title. simon suggests using the wpdc_publish_format_title filter to achieve this, providing an example code snippet. Kayla thanks simon for the pointer and later confirms in post #4 that the solution works, although it has the same field data save timing issues as displaying custom fields in the content when auto-publishing is enabled, as discussed in another topic.
Try hooking into the wpdc_publish_format_title filter. It’s passed two arguments: $title and $post_id.
Something like this should work:
add_filter( 'wpdc_publish_format_title', 'wpdc_custom_publish_format_title', 10, 2 );
function wpdc_custom_publish_format_title( $title, $post_id ) {
if ( get_post_meta( $post_id, 'your_meta_key', true ) ) {
// Modify $title here.
}
return $title;
}
I will try this out as soon as I can, thank you for the pointer!
Works great! This has the same field data save timing issues as displaying custom fields in the content when auto-publishing is enabled but the titles update as expected with this lag in mind. Thanks!