Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) WordPress Create TagSee more WordPress ExamplesDemonstrates how to create a new tag in Wordpress, or to find the ID of an existing tag. For more information, see https://wordpress.org/plugins/application-passwords/
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW json; HCkHttpResponseW resp; HCkJsonObjectW jResp; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // Use your WordPress login, such as "admin", not the application name. CkHttpW_putLogin(http,L"wp_username"); // Use the application password, such as "Nths RwVH eDJ4 weNZ orMN jabq" // See WordPress Application Passwords Plugin CkHttpW_putPassword(http,L"app_password"); CkHttpW_putBasicAuth(http,TRUE); // Create the tag "ChatGPT" if it does not already exist. json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"name",L"ChatGPT"); // This will create the tag if it does not yet exist. // If the tag already exists, then a 400 status code is returned. // If the tag deoes not yet exist, then a 201 status code is returned. resp = CkHttpW_PostJson3(http,L"https://cknotes.com/wp-json/wp/v2/tags",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_Load(jResp,CkHttpResponseW_bodyStr(resp)); // Check if the tag already exists.. if (CkHttpResponseW_getStatusCode(resp) == 400) { if (CkJsonObjectW_HasMember(jResp,L"code") == TRUE) { if (CkJsonObjectW_StringOfEquals(jResp,L"code",L"term_exists",TRUE) == TRUE) { // The tag already exists. wprintf(L"The tag already exists.\n"); wprintf(L"Tag ID: %d\n",CkJsonObjectW_IntOf(jResp,L"data.term_id")); CkJsonObjectW_Dispose(jResp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkJsonObjectW_Dispose(jResp); return; } } // Fall through to check for errors. } // Check for errors. if (CkHttpResponseW_getStatusCode(resp) != 201) { wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); wprintf(L"status code = %d\n",CkHttpResponseW_getStatusCode(resp)); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkJsonObjectW_Dispose(jResp); return; } // We get here if the tag was created.. wprintf(L"The tag was created.\n"); wprintf(L"Tag ID = %d\n",CkJsonObjectW_IntOf(jResp,L"id")); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.