-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordPress_Add_post_API.ps1
More file actions
39 lines (22 loc) · 923 Bytes
/
WordPress_Add_post_API.ps1
File metadata and controls
39 lines (22 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("user:pass")))
$header = @{
Authorization=("Basic {0}" -f $base64AuthInfo)
}
$params = @{
title = "test Rest API post 5"
content = "test Rest API post content"
status = 'publish'
featured_media = '12'
}
$params1=$params|ConvertTo-Json
$response = Invoke-RestMethod -Method post -Uri http://wordpress_page.pl/wp-json/wp/v2/posts -ContentType "application/json" -Body $params1 -Headers $header -UseBasicParsing
#Opublikuj na glownej
$params_meta = @{
key = "ex_show_in_homepage"
value = "Yes"
}
$params_meta1=$params_meta|ConvertTo-Json
$id = $response.id
$url = "http://wordpress_page.pl/wp-json/wp/v2/posts/$id/meta"
Invoke-RestMethod -Method post -Uri $url -ContentType "application/json" -Body $params_meta1 -Headers $header -UseBasicParsing