0

I'm teaching myself how to build Wordpress plugins. I found a great guide to creating a Wordpress Meta Box and saving the form input from it.

https://themefoundation.com/wordpress-meta-boxes-guide/

I want to send the entered and saved form input from the Meta Box that is in the Post edit view of Wordpress to the Wordpress RSS in its own tag. So when the user publishes the Post the Meta Box form data saves and adds the saved input to the post Wordpress RSS nested in its own tag.

This is the code that saves the form input:

function prfx_meta_save( $post_id ) {

// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';

// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
    return;
}

// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'meta-text' ] ) ) {
    update_post_meta( $post_id, 'meta-text', sanitize_text_field( $_POST[ 'meta-text' ] ) );
}

}
add_action( 'save_post', 'prfx_meta_save' );
1

1 Answer 1

0

I figured out the code to add to the above tutorial article about creating a Meta Box that saves values. This code puts the post meta into its own tag in the RSS. I added the post meta "meta-text" to the code below to work with the tutorial.

add_action('rss2_item', 'add_my_custom_field_node');

function add_my_custom_field_node() {
global $post;
$metaValue = get_post_meta($post->ID, 'meta-text', true);
if(!empty($metaValue)):
    echo("<my-custom-field>{$metaValue}</my-custom-field>");
endif;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.