save_post() on Menu Save

As Mr. Peattie and Mr. Nowell pointed out, you should check the post type as one of the first things in your save_post function. Here’s couple of ways how to do it, add_action( ‘save_post’, ‘prefix_my_save_post_action’, 10, 3 ); function prefix_my_save_post_action( $post_id, $post, $update ) { // Check for single post type if ( ‘my_post_type’ !== … Read more

Save_post acf data not updating category of post type

You can not use is_single() conditional tag here. You can check the type of post in the function this way: add_action( ‘save_post’, ‘set_genre_on_save’, 20, 3 ); function set_genre_on_save( $post_id, $post, $update ) { if ($post->post_type != ‘hvm’) return; // … } You can also attach the function to the action hook save_post_{post_type}, which is triggered … Read more

Get Category in save_post Hook

Unfortunately, no success after a test 🙁 I put the follwing: if ( get_post_status( $post_id ) === ‘publish’ ) { $post_title = apply_filters(‘the_title’, get_post_field(‘post_title’, $post_id)); $post_content = apply_filters(‘the_content’, get_post_field(‘post_content’, $post_id)); $taxonomy = “category”; $args = array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’); $cat = wp_get_post_terms( $post_id, $taxonomy, $args ); $categorie = $cat[0]->name; I get the count … Read more

How to check for duplicate record before saving a Custom Post Type

See this answer for solution, see comments there about error messages. That should work with Classic editor. It could work with Gutenberg too, but it would need additional effort to get correct error messages. UPDATE: If using classic editor and preventing publishing of invalid records is enough, you can use this code: function my_save_post($post_id) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)