Title: WordPress API Call
Last modified: July 3, 2018

---

# WordPress API Call

 *  [jonnyni](https://wordpress.org/support/users/jonnyni/)
 * (@jonnyni)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/wordpress-api-call/)
 * Hi
 * I was wondering if someone could help fix a problem I’m having with sending emails
 * I’ll try and explain it the best I can, I have developed a website for a golf
   club I’m a member at. The first part is just a basic WordPress site that displays
   information about the club and displays competition results, the competition 
   results are pulled from a MySQL DB using embedded PHP Code (XYZ PPH Code Plugin)
 * The second part I have written myself and is used to add competition results 
   to the DB. When a new competition is added to the DB is also sends a API call
   to WordPress and this will then post the news on the news feed and tag it with
   the correct category
 * Results – Men
    Results – Ladies Results – Juniors
 * (Under Posts and Categories)
 * This is the bit I’m having issues with, in Email Subscribers I have created 4
   groups people can subscribe to
 * Club News
    Results – Men Results – Ladies Results – Juniors
 * I also have 2 templates, one for Club News and one for Results Men\Ladies\Juniors
 * Next up I have 4 post notifications
 * Club News Template \ Club News Subscribers Group \ Club News Post Categories
   
   Results Template \ Results – Men Subscribers Group \ Results – Men Post Categories
   Results Template \ Results – Ladies Subscribers Group \ Results – Ladies Post
   Categories Results Template \ Results – Juniors Subscribers Group \ Results –
   Juniors Post Categories
 * If I login to the WordPress admin site and create and new post and say tag it
   with Results – Men, it will then post the news, email all subscribers to Results–
   Men and also use the correct template, so I know the system is working fine
 * When I use the API to add the news post, it will post the news fine, have the
   correct category of Results – Men, send the email but it won’t have the correct
   template and something I haven’t checked yet is it emailing the correct people.
   It will have the Club News template
 * This is the code used to post the news
 *     ```
       if ($agcfcat == "Men")
       {
       $wpcat = "3"; \\Results - Men
       }
   
       if ($agcfcat == "Ladies")
       {
       $wpcat = "4"; \\Results - Ladies
       }
   
       if ($agcfcat == "Junior")
       {
       $wpcat = "5"; \\Results - Juniors
       }	
   
       $curl = curl_init();
   
       curl_setopt_array($curl, array(
         CURLOPT_URL => "http://www.***.com/index.php?rest_route=/wp/v2/posts/",
         CURLOPT_RETURNTRANSFER => true,
         CURLOPT_ENCODING => "",
         CURLOPT_MAXREDIRS => 10,
         CURLOPT_TIMEOUT => 30,
         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
         CURLOPT_CUSTOMREQUEST => "POST",
         CURLOPT_POSTFIELDS => "------WebKitFormBoundary*****\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n$agcfname\r\n------WebKitFormBoundary*****\r\nContent-Disposition: form-data; name=\"content\"\r\n\r\n<p style='text-align: left'>Results are in:</p><br><p style='text-align: center;'><span style='font-family: tahoma; font-size: 40pt; color: #739250;'><strong>Antrim Golf Club</strong></span><br><span style='font-family: tahoma; font-size: 25pt; color: black;'><strong>$agcfname</strong></span><br><span style='font-family: tahoma; font-size: 12pt; color: #747474;'><strong>$agcfday $agcmonthtext $agcfyear</strong></span><br><span style='font-family: tahoma; font-size: 14pt; color: black;'><strong>$agcftype - $agcftees - $agcfholes Holes</strong></span></p><br><p style='text-align: center;'><!--more--></p>[auto-iframe link=http://www.***.com/view_results.php?id=$agcidused&header=no autosize=yes]\r\n------WebKitFormBoundary*****\r\nContent-Disposition: form-data; name=\"excerpt\"\r\n\r\n<p style='text-align: left'>Results are in:</p><br><p style='text-align: center;'><span style='font-family: tahoma; font-size: 40pt; color: #739250;'><strong>Antrim Golf Club</strong></span><br><span style='font-family: tahoma; font-size: 25pt; color: black;'><strong>$agcfname</strong></span><br><span style='font-family: tahoma; font-size: 12pt; color: #747474;'><strong>$agcfday $agcmonthtext $agcfyear</strong></span><br><span style='font-family: tahoma; font-size: 14pt; color: black;'><strong>$agcftype - $agcftees - $agcfholes Holes</strong></span></p><br><p style='text-align: center;'><!--more--></p>[auto-iframe link=http://www.***.com/view_results.php?id=$agcidused&header=no autosize=yes]\r\n------WebKitFormBoundary*****\r\nContent-Disposition: form-data; name=\"status\"\r\n\r\npublish\r\n------WebKitFormBoundary*****\r\nContent-Disposition: form-data; name=\"categories\"\r\n\r\n$wpcat\r\n------WebKitFormBoundary*****--",
         CURLOPT_HTTPHEADER => array(
           "Authorization:  ***",
           "Cache-Control: no-cache",
           "Postman-Token: ***",
           "content-type: multipart/form-data; boundary=----WebKitFormBoundary*****"
         ),
       ));
   
       $response = curl_exec($curl);
       $err = curl_error($curl);
   
       curl_close($curl);
   
       if ($err) {
         echo "cURL Error #:" . $err;
       } else {
         echo "<br>News Posted<br><br>";
       }
       ```
   
 * Clearly I’m missing something, should I be adding anything else?
 * Title
    Content Excerpt Status Categories
 * Any help would be great
 * Thanks
    -  This topic was modified 7 years, 11 months ago by [jonnyni](https://wordpress.org/support/users/jonnyni/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [7 years, 11 months ago](https://wordpress.org/support/topic/wordpress-api-call/#post-10464967)
 * Don’t create multiple topics for the same thing. I’ve removed your new topic.
 *  Plugin Author [Icegram](https://wordpress.org/support/users/icegram/)
 * (@icegram)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/wordpress-api-call/#post-10483420)
 * [@jonnyni](https://wordpress.org/support/users/jonnyni/) ,
 * We have got your ticket in our system and we will send you reply from there.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WordPress API Call’ is closed to new replies.

 * ![](https://ps.w.org/email-subscribers/assets/icon-256x256.png?rev=2274172)
 * [Email Subscribers & Newsletters - Email Marketing, Post Notifications & Newsletter Plugin for WordPress](https://wordpress.org/plugins/email-subscribers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/email-subscribers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/email-subscribers/)
 * [Active Topics](https://wordpress.org/support/plugin/email-subscribers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/email-subscribers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/email-subscribers/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [Icegram](https://wordpress.org/support/users/icegram/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/wordpress-api-call/#post-10483420)
 * Status: not resolved