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 – JuniorsI 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 CategoriesIf 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 => "https://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=https://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=https://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
CategoriesAny help would be great
Thanks
- The topic ‘WordPress API Call’ is closed to new replies.