I'm probably doing something stupid.
But i have the following working code, (this a small (but working) part of the code) if i have this code in my functions.php it works fine, but when i add it in a custom plugin, it does not
function update_booklink_field( $post_id ) {
if( ! ( wp_is_post_revision( $post_id) || wp_is_post_autosave( $post_id ) ) ) {
update_post_meta( $post_id, 'prijstest', 'testvalue' );
}
}
add_action( 'save_post', 'update_booklink_field' );
This is my code in the plugin, is there something obvious i am missing? Or are there extra steps i need to take to trigger a function when it is in a plugin?
<?php
/**
* Plugin Name: aaautofill
*/
function update_booklink_field( $post_id ) {
if( ! ( wp_is_post_revision( $post_id) || wp_is_post_autosave( $post_id ) ) ) {
update_post_meta( $post_id, 'prijstest', 'testvalue' );
}
}
add_action( 'save_post', 'update_booklink_field' );
?>
EDIT:
What i found out so far: if i move
add_action( 'save_post', 'update_booklink_field');
to the functions file, then it works. The plugin is activated, but the save_post just doesnt run when its in my plugin file. i really have 0 clue what is causing this :/
edit 2:
Basicly the function doesnt seem to have an issue, because if i change the location of when its loaded (in the fucntion.php) it works fine.
- Issue is the add_action save hook (probably) because
- plugin is live/active/works (tested with var dumbs)
- the function also works, if the add_action is in the functions.php vs when it's in the plugin file.
- no other plugins are live, default twenty seventeen, theme
Does this mean it has to do with the order in which the things are loaded? (or am i overlooking something stupid?)
Edit 3, i found it/got it working if i changed the save_post line to:
add_action( 'save_post', 'update_booklink_field', 50 , 50 );
it works