$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - Add Wordpress Meta Box saved form input to Wordpress RSS feed|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - Add Wordpress Meta Box saved form input to Wordpress RSS feed

matteradmin8PV0评论
This question already has an answer here: Give extra post-meta to RSS feeds (1 answer) Closed 6 years ago.

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.

/

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' );
This question already has an answer here: Give extra post-meta to RSS feeds (1 answer) Closed 6 years ago.

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/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' );
Share Improve this question asked Nov 15, 2018 at 19:01 Paul HenshawPaul Henshaw 13 bronze badges 1
  • Here, this should help :) codex.wordpress/Customizing_Feeds – admcfajn Commented Nov 15, 2018 at 19:17
Add a comment  | 

1 Answer 1

Reset to default 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;
}
Post a comment

comment list (0)

  1. No comments so far