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.
- Indeed, I was using the wrong variable in the first
ifclause. Solution: In the array feedingwp_update_post(), changing'ID' => $quote_id,to'ID' => $post_id,succeeded in helping the posts transition topublishat the end. This was just a mistake on my part, really. - However, then the WP To Twitter plugin was not seeing the post at all as
publishwas fired. Solution: It took changing the method of status transitioning fromwp_update_posttowp_publish_postto 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.