Bu cevap, konu sahibi tarafından kabul edilebilir bir cevap olarak işaretlendi.
Bu kodu sadece şu andan sonra eklediğim makalelerde çalışacak şekilde dizayn edebilecek birisi var mı acaba ? Kodu eklemeden önceki makaleleri ellemeyecek yani. ( Ücretli )
Bugünün tarihinden sonraki postları çekmek işini görmez mi hocam? Aşağıdaki şekilde güncellediğinizde döngüye sadece 2021-10-21 tarihi ve sonra ki postları dahil ediyor. Bugünü de hariç bırakması için inclusive yi false yapabilirsin.
function update_focus_keywords() {
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'post',
'date_query' => array(
array(
'after' => '2021-10-21',
'inclusive' => true,
),
),
));
foreach($posts as $p){
// Checks if Rank Math keyword already exists and only updates if it doesn't have it
$rank_math_keyword = get_post_meta( $p->ID, 'rank_math_focus_keyword', true );
if ( ! $rank_math_keyword ){
update_post_meta($p->ID,'rank_math_focus_keyword',strtolower(get_the_title($p->ID)));
}
}
}
add_action( 'init', 'update_focus_keywords' );