WordPress publish_post hook not getting featured image and meta on first publish, but works on updating title

I don’t know if it’s the Gutenberg editor or if it’s the hook publish_post The hook itself works, and if you used the old WordPress post editor, then the issue in question would not happen. So you can say that it’s the Gutenberg/block editor. why it’s not returning the meta and featured image Because Gutenberg … Read more

Custom meta box values are not getting saved for my custom post type

but remaining values (checkbox, select, images) are not getting saved I believe those fields are also getting saved, but you are just not displaying them correctly. And you should always escape input/textarea values, e.g. use esc_attr() for single-line inputs and esc_textarea() for textareas (multi-line inputs). So to make your code work correctly, try these: First … Read more

How check if a post is saved from backend or frontend?

I would add some hidden input field to frontend form, and check for its presence in the save_post hook. … <input type=”hidden” name=”saved-on-frontend” value=”1″> … And then check for it in that hooked function: function my_save_hook() { if( isset( $_POST[‘saved-on-frontend’] ) ) { return; // don’t do anything … } } add_action( ‘save_post_CUSTOM_POST_TYPE’, ‘my_save_hook’ );

Update current WP post every 3 minutes [closed]

Classic Editor: autosave.js file setInterval(function () {document.getElementById(“publish”).click()}, 300000); php function // Load js file on specific post type in class editor function load_js_file_classic_editor( $hook ) { global $post; if ( $hook == ‘post-new.php’ || $hook == ‘post.php’ ) { if ( ‘post’ === $post->post_type ) { wp_enqueue_script( ‘myautosave’, get_stylesheet_directory_uri().’/includes/js/autosave.js’ ); } } } add_action( ‘admin_enqueue_scripts’, … Read more

Migrating from metaboxes to wp_editor()

It works just the same like a regular textarea with the exception of the data being escaped so when you call for the saved data just make sure to decode the html entities using html_entity_decode here is a very simple demo class, take a look at how the field is created. if (!class_exists(‘wp_editor_meta_box’)){ class wp_editor_meta_box{ … Read more

‘save_post’ hook not working in WP 3.5

attachment_fields_to_save is still called. Just tried out this on my wordpress 3.5. installation and the following code killed wordpress when saving an image. add_filter(‘attachment_fields_to_save’, function() { die(‘attachment_fields_to_save’); });

where does this $post_id come from?

It comes from wp_insert_post(), where do_action() is called with two additional parameters: do_action(‘save_post’, $post_ID, $post); So it is not you who adds the parameters, it is WordPress. If you register your callback with the fourth parameter set to 2 … add_action( ‘save_post’, ‘mytestfunc’, 10, 2 ); … you will even get the complete $post object: … Read more

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