Filter to Add Custom Fields to Embeddings Content

Filter to Add Custom Fields to Embeddings Content

Learn how to dynamically append custom meta information to WordPress post content using pngx_volt_vectors_post_loader_content and pngx_volt_vectors_post_loader_content_type_{$post_type} filters. This tutorial provides a step-by-step guide to modify post contents for all or specific post types, enhancing flexibility in content management.

For both snippet change additional_info to the name of you custom field. Multiple fields can be included in the filter.

This filter runs on all embeddings post types and will add the content before clean up and conversion to markdown happens. HTML can be included here.

/**
 * Append custom meta to post content for all post types.
 *
 * @since 0.1.0
 *
 * @param string  $content The original content.
 * @param WP_Post $post    The post object.
 *
 * @return string Modified content with appended custom meta.
 */
function pngx_volt_append_meta_to_content( $content, $post ) {
    $additional_info = get_post_meta( $post->ID, 'additional_info', true );
    return $content . ' ' . $additional_info;
}
add_filter( 'pngx_volt_vectors_post_loader_content', 'pngx_volt_append_meta_to_content', 10, 2 );

This filter runs on Posts only. Change post to page or another custom post type to target it specifically.pngx_volt_vectors_post_loader_content_type_post

/**
 * Append custom meta to post content for a specific post type.
 *
 * @since 0.1.0
 *
 * @param string  $content The original content.
 * @param WP_Post $post    The post object.
 *
 * @return string Modified content with appended custom meta.
 */
function pngx_volt_append_meta_to_post_content( $content, $post ) {
    if ( 'post' === $post->post_type ) {
        $additional_info = get_post_meta( $post->ID, 'additional_info', true );
        return $content . ' ' . $additional_info;
    }
    return $content;
}
add_filter( 'pngx_volt_vectors_post_loader_content_type_post', 'pngx_volt_append_meta_to_post_content', 10, 2 );

Change the priority from 10 to 9 if you want to add the content before the categories and tags are added to posts.