I would like to know if there is a way to connect the WordPress Rest API and Flarum so that my blog posts are automatically published on Flarum as a new discussion.
I think this would be a good idea for many WordPress sites to implement Flarum as a forum system.
Maybe something like this, but I am not able to get WordPress to choose the chosen tag.
function publish_in_flarum($post_ID) {
$post = get_post($post_ID);
$title = $post->post_title;
$excerpt = $post->post_excerpt;
$link = get_permalink($post_ID);
$data = [
"data" => [
"type" => "discussions",
"attributes" => [
"title" => $title,
"content" => "$extracto[Leer más]($link)"
]
]
];
$ch = curl_init("domain/api/discussions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: API KEY GENERATED",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
}
add_action('publish_post', 'publish_in_flarum');