Admin notice on wp_insert_post

Hooks cannot be added directly inside functions. Using do_action, you can invoke a custom hook. In your case try out the below solution: add_action( ‘wp_insert_post’, ‘automate_intercom’, 10, 3 ); function automate_intercom( $post_id, $post, $update ) { if ( $post->post_status == ‘publish’ && $post->post_type == ‘help-center’ ) { $someCondition = ”; if ( $someCondition !== ” … Read more

Using wp_insert_post to create custom posts with ACF image field

ACF has documentation for creating a form on the frontend. I would stick to their suggestions. I was able to create this by assigning my field group for the form to the custom post type and using a unique template page for the form. <?php /** * Template Name: Form Page Template */ ?> … Read more

Can’t send form data to wpdb when URL has query string

I see a few issues with the code: First, the form action is not set correctly. It should be something like: <form action=”<?php echo esc_url( get_the_permalink() ); ?>” method=”post”> In the PHP code, you are using the wrong table name. You are using the table name ‘invites’ instead of ‘rsvp’. You should change this line: … Read more

PHP – Multiple variables in insert post array

$post_id = wp_insert_post( array( ‘comment_status’ => ‘open’, ‘ping_status’ => ‘closed’, ‘post_author’ => $current_user->ID, ‘post_name’ => $slug, ‘post_title’ => $pollq_question, ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘post_content’ => $_POST[‘poll-description’] . ‘[poll id=’ . $latest_pollid . ‘]’ ) );

Suitable hook when creating, updating and deleting posts programmatically

Hooks are not for deleting or creating posts, they are kind of event listeners. For example ‘delete_post’: “Fires immediately before a post is deleted from the database.” [] You need to use the WordPress REST API: This article by Misha Rudrastyh gives a good intro:

Multipe array in meta_input

In your 2nd code snippet, you’re redefining $post_args for each $movie. Try this instead: $post_args = array(); foreach($movies as $movie) { $i++; $post_args[] = array( array( ‘key’ => ‘title’ . $i, ‘value’ => $movie[‘title’] ), array( ‘key’ => ‘qty’ . $i, ‘value’ => $movie[‘qty’] ), array( ‘key’ => ‘desc’ . $i, ‘value’ => $movie[‘desc’] ) … Read more

Create Page with Template File from Plugin Folder

It is probably wp_insert_post can’t recognize your template. You need to include it in the list of the templates. function wpse410645_add_plugin_template( $page_templates ) { $page_templates[plugin_dir_path( __FILE__ ) . ‘/templates/mytemplate.php] = ‘My Template Name’; return $page_templates; } add_filter( ‘theme_page_templates’, ‘wpse410645_add_plugin_template’ );