Loading...
Loading...
Publish and manage posts on a self-hosted WordPress site via the WordPress REST API. Use when the user mentions WordPress, wp-admin, publishing / updating a blog post, managing categories or tags, or uploading media to their own WordPress site.
npx skill4agent add acedatacloud/skills wordpress/wp-json/wp/v2curl + jq$WORDPRESS_SITE_URLhttps://blog.example.com$WORDPRESS_USERNAME$WORDPRESS_APP_PASSWORDusername:app_password# Normalize the site URL (strip a trailing slash) and build the API base.
SITE="${WORDPRESS_SITE_URL%/}"
API="$SITE/wp-json/wp/v2"
# -u sends HTTP Basic auth; --fail-with-body surfaces the JSON error body on 4xx/5xx.
WP=(curl -sS --fail-with-body -u "$WORDPRESS_USERNAME:$WORDPRESS_APP_PASSWORD"){"code": "...", "message": "...", "data": {"status": 401}}message| HTTP | Meaning | What to tell the user |
|---|---|---|
| 401 | | Application Password wrong or revoked → regenerate it and reconnect the WordPress connector |
| 403 | | The user's role can't publish; needs Author/Editor/Admin, or Application Passwords are disabled on the site |
| 404 | | REST API disabled or a security plugin blocks |
| 400 | | Bad field (e.g. unknown category id) → fix and retry |
is HTML, not Markdown. Convert Markdown to HTML first (content, or a simple converter). Raw Markdown renders literally.pandoc -f markdown -t html
"${WP[@]}" "$API/users/me" | jq '{id, name, slug, roles: (.roles // [])}'status=publishstatus=draftjq -n --arg t "国内如何稳定调用 Claude API" \
--arg c "<p>正文 HTML……</p>" \
--arg s "draft" \
'{title:$t, content:$c, status:$s}' \
| "${WP[@]}" -X POST "$API/posts" \
-H "Content-Type: application/json" -d @- \
| jq '{id, status, link, edit: "\(env.WORDPRESS_SITE_URL)/wp-admin/post.php?action=edit&post=\(.id)"}'jq -n --arg t "标题" --arg c "<p>正文</p>" --arg e "一句话摘要" \
'{title:$t, content:$c, excerpt:$e, status:"draft",
categories:[5], tags:[12,34]}' \
| "${WP[@]}" -X POST "$API/posts" -H "Content-Type: application/json" -d @- \
| jq '{id, status, link}'POST $API/posts/<id>{"status":"publish"}POST $API/posts/<id>"${WP[@]}" -X DELETE "$API/posts/<id>""${WP[@]}" "$API/posts?per_page=10&status=publish,draft&_fields=id,title,status,link,date" \
| jq '.[] | {id, title: .title.rendered, status, link, date}'&page=2X-WP-TotalPages-D -# List existing
"${WP[@]}" "$API/categories?per_page=100&_fields=id,name,slug" | jq '.[] | {id, name}'
"${WP[@]}" "$API/tags?per_page=100&_fields=id,name,slug" | jq '.[] | {id, name}'
# Create one (returns its id)
jq -n --arg n "AI 教程" '{name:$n}' \
| "${WP[@]}" -X POST "$API/categories" -H "Content-Type: application/json" -d @- \
| jq '{id, name}'{"code":"term_exists", ... "data":{"status":400,"term_id":<id>}}.data.term_idFILE="./cover.png"
NAME="$(basename "$FILE")"
MEDIA_ID=$("${WP[@]}" -X POST "$API/media" \
-H "Content-Disposition: attachment; filename=\"$NAME\"" \
-H "Content-Type: image/png" \
--data-binary @"$FILE" | jq -r '.id')
echo "media id=$MEDIA_ID"
# Attach as the post's featured image:
# add "featured_media": <MEDIA_ID> to the post body.http:///wp-jsonrest_no_routeabcd efgh ijkl mnopcurl -uwp-adminpublish_artifactpublish_artifact(kind="article", channel="wordpress", title="<title>", url="<the REAL returned URL>", status="delivered")status="failed"_shared/artifacts.md