Chức năng chính
Mục đích để cập nhật ngày đăng những sản phẩm và bài viết đã để dưới dạng riêng tư lâu ngày được cập nhật thành ngày hiện tại. Giúp cho google hiểu được những nội dung này là nội dung mới, chứ không phải nội dung cũ.
Cách sử dụng
Các bạn bỏ code vào file function.php và lưu lại. Các biến cần lưu ý
post_type: Đổi thành post type cần random: vd: post cho bài viết, product cho sản phẩmpost_status: Trạng thái của nội dung, bạn có thể thay thành publish để cập nhật những nội dung đã được xuất bảnbulk_update_product_dates(0, 60);: Số 0 thể hiện cho số lượng nội dung sẽ bỏ qua, và 60 thể hiện số lượng nội dung chạy mỗi lầnorderby: sắp xếp điều kiện, trong code là theo ngày thángorder: sắp xếp thứ tự, trong code đang set theo thứ tự tăng dần
các chỉ số bạn cần quan tâm thì mình đã chú thích rõ trong code, bạn chỉ cần thay theo ý bạn là ok. Nên giới hạn số lượng mỗi lần chạy tuỳ vào cấu hình server và gỡ code sau khi đã thực hiện xong. Chúc bạn thành công nhé!
function bulk_update_product_dates($offset_products, $number_to_update) {
global $wpdb;
// Get the current date and time
$current_date = current_time('mysql');
// Fetch product IDs ordered by date (oldest first)
$product_ids = $wpdb->get_col("
SELECT ID
FROM {$wpdb->posts}
WHERE post_type = 'product' AND post_status = 'private'
ORDER BY post_date ASC
");
// Update the published dates for the specified number of products
for ($i = $offset_products; $i < $offset_products + $number_to_update && $i < count($product_ids); $i++) {
$product_id = $product_ids[$i];
// Update the product published date directly in the database
$wpdb->query("
UPDATE {$wpdb->posts}
SET post_date = '$current_date',
post_date_gmt = '$current_date'
WHERE ID = $product_id
");
echo "Product $product_id updated successfully.<br>";
}
echo "Product published dates updated successfully.<br>";
}
bulk_update_product_dates(0, 60);
Your article helped me a lot, is there any more related content? Thanks! https://www.binance.info/register?ref=IHJUI7TF
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Interesting take on bankroll management! Seeing platforms like sugal777 games prioritize user experience-easy access is key for consistent play, just like a well-managed fund. A safe, enjoyable environment is crucial for long-term success!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.com/hu/register?ref=IQY5TET4
That’s a great point about fair gaming – transparency is huge these days! Seeing platforms like AH88 PH embrace blockchain for provably fair results is promising. Curious to try it out – checking out the ah88 ph app download apk now! Seems easy with GCash deposits too.