How to change post status from “draft” to “publish”?

A two-part answer below –

As above: the broad solution was to save the posts first as draft, then update them with the custom fields and terms, and only then set them to publish.

As I said, the above code modification had succeeded in setting the posts to draft but not in transitioning them to publish, they were stuck.

  1. Indeed, I was using the wrong variable in the first if clause. Solution: In the array feeding wp_update_post(), changing 'ID' => $quote_id, to 'ID' => $post_id, succeeded in helping the posts transition to publish at the end. This was just a mistake on my part, really.
  2. However, then the WP To Twitter plugin was not seeing the post at all as publish was fired. Solution: It took changing the method of status transitioning from wp_update_post to wp_publish_post to make it see everything…

That is, from…

                // Change from draft to published
                $my_post = array(
                  'ID'           => $post_id,
                  'post_type' => 'quote',
                  'post_status'   => 'publish',
                );
                // Update the post into the database
                wp_update_post( $my_post );

to…

                wp_publish_post( $post_id );

After doing that, it now looks like it works out okay – the plugin is tweeting out all the post fields (standard and custom) that I need.

It would be useful to read some things about the differences between wp_update_post and wp_publish_post, because I had read some information on here about discrepancies, with a recommendation to use the former.