• 21-10-2021, 03:20:55
    #10
    mustafabosnak adlı üyeden alıntı: mesajı görüntüle
    Fonksiyon daha önce oluşturulduğu içinde olabilir farklı bir isim verip deneyebilir misiniz hocam?
    [COLOR=#515365][FONT=consolas]function update_focus_keywords2() {[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]    $posts = get_posts(array([/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]    'posts_per_page'    => -1,[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]    'post_type'        => 'post' // Replace post with the name of your post type[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]    ));[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]    foreach($posts as $p){[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]        // Checks if Rank Math keyword already exists and only updates if it doesn't have it[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]        $rank_math_keyword = get_post_meta( $p->ID, 'rank_math_focus_keyword', true );[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]    if ( ! $rank_math_keyword ){[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]            update_post_meta($p->ID,'rank_math_focus_keyword',strtolower(get_the_title($p->ID)));[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]        }[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]    }[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]}[/FONT][/COLOR]
    [COLOR=#515365][FONT=consolas]add_action( 'init', 'update_focus_keywords2' );[/FONT][/COLOR]
    gibi.
    Caxing adlı üyeden alıntı: mesajı görüntüle
    functions.php'ye eklemeyi denediniz mi ?
    Adilhanomer adlı üyeden alıntı: mesajı görüntüle
    Sayfanın en üstüne aşağıdaki kodu eklediğinizde 500 hatasının php çıktısını görebilmeniz lazım.
    ini_set('display_errors',1);
    error_reporting(E_ALL);
    emrenogay adlı üyeden alıntı: mesajı görüntüle
    Kodda bir hata göremedim ancak eklediğiniz yer autoload olmuyor olabilir. Çalıştığınız PHP dosyasına include rtrim($_SERVER['DOCUMENT_ROOT'],'/') . '/wp-load.php'; kodunu ekleyip öyle çalışmayı deneyin.
    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 )
  • 21-10-2021, 03:38:28
    #11
    Bu cevap, konu sahibi tarafından kabul edilebilir bir cevap olarak işaretlendi.
    VelihanD adlı üyeden alıntı: mesajı görüntüle
    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' );
  • 21-10-2021, 03:55:30
    #12
    mustafabosnak adlı üyeden alıntı: mesajı görüntüle
    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' );
    PM ile dönüş yaptım hocam.