wadethefade
Forum Replies Created
-
Sure! Glad to help.
No matter how you get the data, all you need to do is make sure you use the built in WP hooks.
//WP Post Array $articleToPost = array( 'post_title' => $post_title, 'post_content' => $post_content, 'post_category' => $cat, 'post_status' => "draft", // Choose: publish, preview, future, etc. 'post_type' => $post_type // Use a custom post type if you want to ); //WP insert post $theId = wp_insert_post($articleToPost); $postToTransition = get_post( $theId ); // Might not need this //Manually Update Post Status. This can be draft to _whatever_ $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $postToTransition->ID)); clean_post_cache($postToTransition->ID); //Might not need this //WP transition post. Make sure this is matches what you did above. This is what BNFW "listens to" to fire a notification. wp_transition_post_status( "publish", "draft", $postToTransition );
I did not need to add the
add_filter( 'bnfw_trigger_insert_post', '__return_true' );
I ended up manually updating the status, and then doing
wp_transition_status
$theId = wp_insert_post($articleToPost); $postToTransition = get_post( $theId ); $wpdb->update($wpdb->posts, array('post_status' => 'pending'), array('ID' => $postToTransition->ID)); wp_transition_post_status( "pending", "draft", $postToTransition );
Getting one notification.
Thank you for your direction and inputs.
But now the post doesn’t actually move off “draft”. :X
WAIT.
THAT DID IT. I guess I had all the pieces but didn’t have them put together at the right times.
I also never thought about querying the post back out with
get_post
before updating it.This gives me a single notification:
$articleToPost = array( 'post_title' => $post_title, 'post_content' => $post_content, 'post_category' => $cat, 'post_status' => "draft", 'post_type' => $post_type ); $theId = wp_insert_post($articleToPost); $postToTransition = get_post( $theId ); wp_transition_post_status( 'pending', $post_status, $postToTransition );
Thanks for the prompt replies
- This reply was modified 6 years, 5 months ago by wadethefade.
I think I tried something similar, but let me see about this. I know I’ve read that bnfw uses transition hooks to fire…
Oh I have also tried – inserting the post as draft with
wp_insert_post
and then doing awp_update_post
that had this directly after it:
wp_transition_post_status( 'pending', $old_status, $postToStatus );
And… I just tried your suggestion: nope, I expected to get a 2nd round of duplicates.. but no change. I still get duplicate emails.
$theId = wp_insert_post($articleToPost); $postToTransition = get_post( $theId ); do_action( "draft_to_{$post_status}", $postToTransition );
Just throwing my situation in here, as its the closest to my issue as I can find.
I want to create this plugin correctly, so I’m asking direction.
I have a simple form (title, post, cat) and on $post I am literally only doing this:$post_status = "pending"; $articleToPost = array( 'post_title' => $post_title, 'post_content' => $post_content, 'post_category' => $cat, 'post_status' => $post_status, 'post_type' => $post_type,); $theId = wp_insert_post($articleToPost);
And I am getting two notifications. I’ve tried:
add_filter( 'bnfw_trigger_insert_post', '__return_true' );
I’ve even tried using
wp_update_post
I’ve even tried doing manual post transitions using
wp_transition_post_status
I’ve seen you mention not creating plugins right in previous duplicate email threads, but what exactly is the correct way of adding an article to only generate one notification via a plugin?
Note: I do not get duplicates in admin.
I’ve been trying to pair this down to the bare minimum in order to figure it out.
- This reply was modified 6 years, 5 months ago by wadethefade.
- This reply was modified 6 years, 5 months ago by wadethefade.
Forum: Plugins
In reply to: [Plugin: NextGEN Gallery] Gallery Not Found in Page after upradeI keep feeling there is a simple fix to this, but I keep coming up against the fact that it it is obviously looking for the Gallery so NextGen is working… but ?
I’m calling it like this:
[ slideshow id=1 width=452 height=340 ]