[WordPress] Scheduled publication of drafts

barber

Junior Member
Joined
Nov 10, 2022
Messages
196
Reaction score
85
I'm looking for a simple plugin to publish for example 2 drafts per day, I know there are many such plugins, but I'm concerned with simplicity because there are 300+ drafts so moving to a calendar or clicking on a draft is not an option. I would like to set it up once so that new entries added by the API are published automatically at intervals. Can you recommend something?
 
WordPress uses a cron system to schedule tasks. Plugins or custom code can be used to schedule post updates. A popular plugin for managing cron jobs is "WP-Cron Control," which allows you to schedule tasks at specific intervals. By specifying a date and time, you can schedule an update to a post.

You can create a custom function that updates a post on a specific schedule if you are comfortable with coding. WordPress hooks, such as wp_schedule_event, are typically used to set up schedules. You can programmatically update the post content within the scheduled function by using WordPress functions like `wp_update_post`. Add this code to your theme's `functions.php` file or create a custom plugin.
 
WordPress uses a cron system to schedule tasks. Plugins or custom code can be used to schedule post updates. A popular plugin for managing cron jobs is "WP-Cron Control," which allows you to schedule tasks at specific intervals. By specifying a date and time, you can schedule an update to a post.

You can create a custom function that updates a post on a specific schedule if you are comfortable with coding. WordPress hooks, such as wp_schedule_event, are typically used to set up schedules. You can programmatically update the post content within the scheduled function by using WordPress functions like `wp_update_post`. Add this code to your theme's `functions.php` file or create a custom plugin.
Does creation date matter?
If I upload 300 post to wordpess (but don't publish it) , can Google know this?
 
Here's the python code that retrieves the list of drafts, then schedules the publication of 2 for each subsequent day, problem solved :)
Python:
import requests
from datetime import datetime, timedelta

# Step 1: Set API credentials
api_url = "api_url = "https://example.com/wp-json/wp/v2""  # Replace with the correct URL
username = "login"
password = "pass"

# Function to download all posts (taking pagination into account)
def get_all_draft_posts(api_url, auth):
    page = 1
    all_posts = []
    while True:
        response = requests.get(f"{api_url}/posts", params={"status": "draft", "page": page, "per_page": 100},
                                auth=auth)
        if response.status_code == 200:
            posts = response.json()
            if not posts:
                break
            all_posts.extend(posts)
            page += 1
        else:
            print(f"Error: {response.status_code}")
            break
    return all_posts


# Step 2: Get a list of posts with 'draft' status
auth = (username, password)
posts = get_all_draft_posts(api_url, auth)

# Step 3: Update post publication dates
if posts:
    # Set start_date to the beginning of the next day
    now = datetime.now()
    start_date = datetime(now.year, now.month, now.day) + timedelta(days=1)

    for i, post in enumerate(posts):
        # Set the publication time to 9:00 a.m. or 3:00 p.m.
        hour_of_publication = 9 if i % 2 == 0 else 15
        new_date = (start_date + timedelta(days=i // 2)).replace(hour=hour_of_publication, minute=0, second=0)

        post_id = post['id']
        data_to_update = {
            "date": new_date.strftime('%Y-%m-%dT%H:%M:%S'),
            "status": "publish"
        }

        response = requests.post(f"{api_url}/posts/{post_id}", json=data_to_update, auth=auth)
        if response.status_code == 200:
            print(f"Post ID {post_id} updated {new_date}")
        else:
            print(f"Post ID update error {post_id}: {response.status_code}")
else:
    print("No posts to update.")
 
I'm looking for a simple plugin to publish for example 2 drafts per day, I know there are many such plugins, but I'm concerned with simplicity because there are 300+ drafts so moving to a calendar or clicking on a draft is not an option. I would like to set it up once so that new entries added by the API are published automatically at intervals. Can you recommend something?
This is perfect for you
https://wordpress.org/plugins/auto-post-scheduler/
 
Back
Top