I'm looping through an API with jobs and creating new posts from it like this:

//fetch jobs and loop through them...
    // check if post title exists, if not add it.
         if ( ! get_page_by_title(html_entity_decode( $post_title ), OBJECT, 'jobs')) :

        // create new post
            $post_id = wp_insert_post( $my_post );
        // set post terms
            wp_set_post_terms( $post_id, $tags);

        // create tweets through webhook via zapier   
            $tweet = 'webhook content here';
            wp_remote_post( $tweet );


This works well for the posts, but for some reason if I'm looping through a 100 jobs, each time a 100 tweets are created and I don't understand why because it's not creating a 100 new posts with the same title.

How do I call the webhook if it's a new job that hasn't been added yet?

  • 1
    I don't see anything wrong with your method, but I wouldn't verify content this way. This is a fairly intense function for just seeing if something already exists. It might be better to store a unique ID or other attribute in postmeta that you could check if it already exists. – MikeNGarrett Apr 17 '19 at 14:42
  • I'm looping through external data sources for workfromhomejobs.me, they don't have identifiers, the title is the only thing I can check against. – Henrik Harju Apr 17 '19 at 15:08
  • I just don't understand why the wp_remote_post is executed, but not wp_insert_post... – Henrik Harju Apr 17 '19 at 15:11
  • You're checking your $post_id? It could be firing, but throwing an error. – MikeNGarrett Apr 17 '19 at 15:24
  • What does $my_post look like? Is html_entity_decode( $post_title ) the same as the title of the newly created post? – Morgan Estes Apr 17 '19 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.