How to pass custom field types and taxonomies to the WordPress plugin?

Our WordPress site is using Pods’ custom post types with custom field types and taxonomies. The custom post types are being detected by the plugin (yay!) and new posts create Discourse topics just fine. However, only the title and description are being posted in the forum topics.

This is fine for a default behavior, but there is any way to make the plugin post selected custom fields and custom taxonomies as well?

2 Likes

Yes. You can customize the discourse_publish_format_html template for a specific post type. See this topic for more details about customizing the templates: WP Discourse template customization

Something like this, added to a plugin, or to your theme’s functions.php file should work. You can use the following tags in the template: {excerpt}, {blogurl}, {author}, {thumbnail}, {featuredimage}


add_filter( 'discourse_publish_format_html', 'wpdc_custom_discourse_publish_format_html' );
function wpdc_custom_discourse_publish_format_html( $output ) {
    global $post;
    if ( 'your_custom_type' === $post->post_type ) {
        // Get the custom fields and taxonomies that you want published from your post, then...
	    ob_start();
	    ?>
        Originally published at: {blogurl}<br><br>
        {excerpt}

	    <?php
	    $output = ob_get_clean();
    }

    return $output;
}
4 Likes

Thank you for your reply. I finally started working on this, adding the function above to my theme’s functions.php. I can add the {featuredimage} just fine, proving that the function itself works. See

However, I am failing at adding my own custom fields. You can see the proof of my failure by the my_tipos($id) string printed below the featured image. I tried many combinations, and I would either get the strings printed or HTTP ERROR 500 when posting an update to the Discourse topic from the WP post.

// Get the custom fields and taxonomies that you want published from your post

How is this done? Could you provide an example, please? For what is worth, this is how that custom field is rendered in the post template:

       $id = get_the_ID();
       $type_of_action = my_tipos($id);
(...)
       <span class="conf-action-type"><?php echo $type_of_action; ?></span>

The result in this case would be “CULTURA - PERIODISMO - EMANCIPACIÓN” – see the WordPress page.

Do you know if you are able to successfully get the custom field data? I looked quickly through the Pods docs. You might be able to get it with this function: pods_field - Pods Framework.

Once you have the field data, the way you are trying to include it in the template seems correct. It can be tricky to figure this kind of thing out on a live website.

2 Likes

After investigating a bit more, I think I need to clean my WP house before attempting to bring those custom fields to Discourse.

my_tipos() is a new function defined to list the items of a custom taxonomy (not a custom field), and I need to make sure that they ar properly defined and call before the WP Discourse plugins calls them.

Sorry for the noise. I will update this thread once I have figured out the solution. Other Pods users are likely to end up in a similar situation.

Meanwhile, the posts with the `{featuredimage} look good enough already. :slight_smile:

1 Like