Custom Meta Box (SELECT2) Not Saving Taxonomy Terms

First of all you saved the the terms value in a post meta table and not following the wordpress conventional method. To make it connect with default category with that post you need to modify your save_post action. Check the modified code. add_action( ‘save_post’, ‘rudr_save_metaboxdata’, 10, 2 ); function rudr_save_metaboxdata( $post_id, $post ) { if … Read more

frontend submit post jQuery clone row won’t save

Double check if your <div id=’repeater’> is properly inside <form> tag of your page ( I assume you’re in a form since your code does not provide an ajax function) and from what you outpup with var_dump($_POST[‘al_ttl’]) it may be the reason of Undefined index: al_ttl. Also note that you’re overwriting the first initialization of … Read more

Changing new post to “pending” on publish – but “Publish failed” – why?

The wp_update_post hook will call the same action twice, as the action save_post_{$post->post_type} is called in this function. I would add remove_action( ‘save_post_tribe_events’, ‘set_to_pending’); before wp_update_post( $post ); and add_action( ‘save_post_tribe_events’, ‘set_to_pending’, 10, 3 ); after it works 🙂 function set_to_pending($id, $post, $update){ $the_post = print_r($post, true); $the_post_author = $post->post_author; $the_post_url = get_edit_post_link($id); $the_post_url = … Read more

When the new post which has no image published, save the specific image as the featured image ( by category )

Your conditional is in trouble. get_the_category() returns an object, use foreach to find the specific category. In addition, you assigned a value to the $categories variable, to compare you must use the comparison operators ( Ex: == or === ) I refactored the code and adapted it to your case, I hope it helps. add_action( … Read more

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