if && problems with transition_post_status

Question

I’m attempting to get this function to work and it seems to not work when put together.
When I just have

 $new_status == 'publish' 

it works, when I use just the second it also works. When I attempt to && them together there seems to be a hiccup.

Also it should be noted that I attempted just to use the

add_action ('publish_tweet', 'twitter_run_when_published');

but that also didn’t work.

Here is the full function that I’m attempting to use, it is from a codex example

function intercept_all_status_changes( $new_status, $old_status, $post ) {
  if ( $new_status == 'publish' && $_POST['post_type'] == 'tweet' ) {
    // Post status changed

  twitter_run_when_published ();

  }
}
  add_action( 'transition_post_status', 'intercept_all_status_changes', 10, 3 );

The twitter_run_when_published works. I know this because individually the if/condition works.

Some quirks:
The function will work if I publish immediately. It does not work when I schedule a future post.

Additional info that might help I attempted these in the code, they did not work.

add_action('publish_tweet', 'twitter_run_when_published');
//possible alts to make it happen only once and not double down

add_action('new_to_publish_tweet', 'twitter_run_when_published');
add_action('draft_to_publish_tweet', 'twitter_run_when_published');
add_action('pending_to_publish_tweet', 'twitter_run_when_published');
add_action('future_to_publish_tweet', 'twitter_run_when_published');
add_action('auto-draft_to_publish_tweet', 'twitter_run_when_published');
add_action('private_to_publish_tweet', 'twitter_run_when_published');
add_action('inherit_to_publish_tweet', 'twitter_run_when_published');
add_action('trash_to_publish_tweet', 'twitter_run_when_published');

Only publishing immediately performs the function mentioned above.

The classic example works.

function intercept_all_status_changes( $new_status, $old_status, $post ) {
  if ( $new_status != $old_status) {
    // Post status changed

    twitter_run_when_published ();

 }
}
add_action( 'transition_post_status', 'intercept_all_status_changes', 10, 3 );

But this will fire off the function multiple times. It doesn’t work in the plugin but will work for sure in the theme.

What am I missing? I’d like to have it so that when an article is published and it meets the custom post type tweet that it performs a function.

EDIT: I was rambling a bit and attempted to clear up a few poorly phrased sentences.

0
, Cody 1 year 2020-07-16T23:10:54-05:00 0 Answers 55 views 0

Leave an answer

Browse
Browse