Чтобы получить сообщения из API WordPress, вы можете использовать различные методы в зависимости от ваших требований. Вот несколько методов с примерами кода:
-
Использование REST API:
import requests # Retrieve all posts response = requests.get('https://your-wordpress-site/wp-json/wp/v2/posts') # Get the JSON data posts = response.json() # Process the posts for post in posts: # Access post properties title = post['title']['rendered'] content = post['content']['rendered'] # ... additional processing -
Использование XML-RPC API:
import xmlrpc.client # Create a server proxy server = xmlrpc.client.ServerProxy('https://your-wordpress-site/xmlrpc.php') # Retrieve posts posts = server.wp.getPosts(0, 'your-username', 'your-password', {'post_type': 'post'}) # Process the posts for post in posts: # Access post properties title = post['post_title'] content = post['post_content'] # ... additional processing -
Использование PHP-библиотеки WP-API:
require_once('wp-load.php'); global $wpdb; // Retrieve posts $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post'"); // Process the posts foreach ($posts as $post) { // Access post properties $title = $post->post_title; $content = $post->post_content; // ... additional processing }
Это всего лишь несколько примеров. В зависимости от языка программирования и библиотек, которые вы используете, доступны и другие методы.