• I am learning WordPress Plugin development. I would like to catch values of MetaBox. I found below code in Plugin development Handbook.

    
    function wporg_save_postdata( $post_id ) {
        if ( array_key_exists( 'wporg_field', $_POST ) ) {
            update_post_meta(
                $post_id,
                '_wporg_meta_key',
                $_POST['wporg_field']
            );
        }
    }
    add_action( 'save_post', 'wporg_save_postdata' );
    

    But in which File should I place these codes ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Without having actually seen any of your code, you’re most likely going to need it in the plugin header file (the file with your plugin name etc.

    • This reply was modified 2 years, 5 months ago by Michael Ott.

    Hi @mabufoysal You can put this code in any files. If you are creating plugin with only one file, then put in that. If you are using multiple files in plugin, place this code in file in which you are adding all actions/filters for your functionality.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Catch metabox values in Plugin’ is closed to new replies.