• 14-05-2023, 00:30:47
    #1
    Merhaba, php sürüm değişikliğinden sonra böyle bir hata almaya başladım:

    Warning: Trying to access array offset on value of type bool in .... on line 161
    Warning: Trying to access array offset on value of type bool in .... on line 165

    Warning: Trying to access array offset on value of type bool in .... on line 166

    Warning: Trying to access array offset on value of type bool in .... on line 167

    İlgili kodu ve satır numarasını belirttim. Yardımcı olur musunuz?


    function ekleme_mt(){
    if(is_category()){
    $term = get_queried_object();  
    $term_image = wp_get_attachment_image_src(get_term_meta(get_queried_object_id(), 'dosya-url', true),'full')[0];       (161 nolu satır burası)
    $term_bilgi = wp_get_attachment_metadata(get_term_meta(get_queried_object_id(), 'dosya-url ', true));
    $post_id = get_term_meta(get_queried_object_id(), 'dosya-url', true);
    echo '<meta property="og:image" content="'.$term_image.'" />
    <meta property="og:image:type" content="'.$term_bilgi["sizes"]["medium"]["mime-type"].'" />
    <meta property="og:image:width" content="'.$term_bilgi["width"].'" />
    <meta property="og:image:height" content="'.$term_bilgi["height"].'" />
    <meta property="og:image:alt" content="'.get_the_excerpt($post_id).'" />
    ';
    }
    }
    
    add_action('wp_head', 'ekleme_mt',9);
  • 14-05-2023, 00:35:43
    #2
    Üyeliği durduruldu
    <?php
    $term_id = get_queried_object_id();
    $attachment_id = get_term_meta($term_id, 'url-dosya', true);
    $image_data = wp_get_attachment_metadata($attachment_id);

    if ($attachment_id && is_array($image_data)) {
    $image_url = wp_get_attachment_image_src($attachment_id, 'full')[0];
    $mime_type = isset($image_data['sizes']['medium']['mime-type']) ? $image_data['sizes']['medium']['mime-type'] : '';
    $width = isset($image_data['width']) ? $image_data['width'] : '';
    $height = isset($image_data['height']) ? $image_data['height'] : '';

    echo '<meta property="og:image" content="' . esc_url($image_url) . '" />' . "n";
    echo '<meta property="og:image:type" content="' . esc_attr($mime_type) . '" />' . "n";
    echo '<meta property="og:image:width" content="' . esc_attr($width) . '" />' . "n";
    echo '<meta property="og:image:height" content="' . esc_attr($height) . '" />
    ' . "n";
    }
    ?>
    bunu deneyin
  • 14-05-2023, 00:44:40
    #3
    Saitama adlı üyeden alıntı: mesajı görüntüle
    <?php
    $term_id = get_queried_object_id();
    $attachment_id = get_term_meta($term_id, 'url-dosya', true);
    $image_data = wp_get_attachment_metadata($attachment_id);

    if ($attachment_id && is_array($image_data)) {
    $image_url = wp_get_attachment_image_src($attachment_id, 'full')[0];
    $mime_type = isset($image_data['sizes']['medium']['mime-type']) ? $image_data['sizes']['medium']['mime-type'] : '';
    $width = isset($image_data['width']) ? $image_data['width'] : '';
    $height = isset($image_data['height']) ? $image_data['height'] : '';

    echo '<meta property="og:image" content="' . esc_url($image_url) . '" />' . "n";
    echo '<meta property="og:image:type" content="' . esc_attr($mime_type) . '" />' . "n";
    echo '<meta property="og:image:width" content="' . esc_attr($width) . '" />' . "n";
    echo '<meta property="og:image:height" content="' . esc_attr($height) . '" />
    ' . "n";
    }
    ?>
    bunu deneyin

    function ekleme_mt(){
    if(is_category()){
    $term_id = get_queried_object_id();
    $attachment_id = get_term_meta($term_id, 'dosya-url', true);
    $image_data = wp_get_attachment_metadata($attachment_id);

    if ($attachment_id && is_array($image_data)) {
    $image_url = wp_get_attachment_image_src($attachment_id, 'full')[0];
    $mime_type = isset($image_data['sizes']['medium']['mime-type']) ? $image_data['sizes']['medium']['mime-type'] : '';
    $width = isset($image_data['width']) ? $image_data['width'] : '';
    $height = isset($image_data['height']) ? $image_data['height'] : '';

    echo '<meta property="og:image" content="' . esc_url($image_url) . '" />' . "n";
    echo '<meta property="og:image:type" content="' . esc_attr($mime_type) . '" />' . "n";
    echo '<meta property="og:image:width" content="' . esc_attr($width) . '" />' . "n";
    echo '<meta property="og:image:height" content="' . esc_attr($height) . '" />
    ' . "n";
    }
    }
    add_action('wp_head', 'ekleme_mt ',9);
    }


    Hocam bu şekilde ekledim Unclosed hatası veriyordu en son bu şekilde düzenledim en alttaki parantezi koydum hata gitti doğru eklemiş miyim?
  • 14-05-2023, 00:48:02
    #4
    Üyeliği durduruldu
    Turgenyev adlı üyeden alıntı: mesajı görüntüle

    function ekleme_mt(){
    if(is_category()){
    $term_id = get_queried_object_id();
    $attachment_id = get_term_meta($term_id, 'dosya-url', true);
    $image_data = wp_get_attachment_metadata($attachment_id);

    if ($attachment_id && is_array($image_data)) {
    $image_url = wp_get_attachment_image_src($attachment_id, 'full')[0];
    $mime_type = isset($image_data['sizes']['medium']['mime-type']) ? $image_data['sizes']['medium']['mime-type'] : '';
    $width = isset($image_data['width']) ? $image_data['width'] : '';
    $height = isset($image_data['height']) ? $image_data['height'] : '';

    echo '<meta property="og:image" content="' . esc_url($image_url) . '" />' . "n";
    echo '<meta property="og:image:type" content="' . esc_attr($mime_type) . '" />' . "n";
    echo '<meta property="og:image:width" content="' . esc_attr($width) . '" />' . "n";
    echo '<meta property="og:image:height" content="' . esc_attr($height) . '" />
    ' . "n";
    }
    }
    add_action('wp_head', 'ekleme_mt ',9);
    }


    Hocam bu şekilde ekledim Unclosed hatası veriyordu en son bu şekilde düzenledim en alttaki parantezi koydum hata gitti doğru eklemiş miyim?
    is_array() hatası tespit ettiydim ben ve son parantez olmaz ve wp_head çağırma hatalı ama tam hakim değilim yanlış yonlendirmeyeyim
  • 14-05-2023, 00:51:24
    #5
    Muhtemelen $term_image değişkeni false olarak ayarlanmış, dolayısıyla bir diziye erişmeye çalışırken bu hataları alıyorsunuz..
    wp_get_attachment_image_src fonksiyonu, aradığınız dosya URL'sini bulamadığında false döndürür. Bu nedenle, get_term_meta işlevinin döndürdüğü sonucu kontrol etmeniz ve ardından wp_get_attachment_image_src işlevinin sonucunu kullanmadan önce boş olup olmadığını kontrol etmeniz gerekir.

    Şöyle deneyin:
    function ekleme_mt(){
        if(is_category()){
            $term = get_queried_object();
            $term_image_id = get_term_meta(get_queried_object_id(), 'dosya-url', true);
            if (!empty($term_image_id)) {
                $term_image = wp_get_attachment_image_src($term_image_id, 'full')[0];
                $term_bilgi = wp_get_attachment_metadata($term_image_id);
                $post_id = $term_image_id;
                echo '<meta property="og:image" content="'.$term_image.'" />
                      <meta property="og:image:type" content="'.$term_bilgi["sizes"]["medium"]["mime-type"].'" />
                      <meta property="og:image:width" content="'.$term_bilgi["width"].'" />
                      <meta property="og:image:height" content="'.$term_bilgi["height"].'" />
                      <meta property="og:image:alt" content="'.get_the_excerpt($post_id).'" />
                ';
            }
        }
    }
    add_action('wp_head', 'ekleme_mt',9);
  • 14-05-2023, 00:55:58
    #6
    zentamedia adlı üyeden alıntı: mesajı görüntüle
    Muhtemelen $term_image değişkeni false olarak ayarlanmış, dolayısıyla bir diziye erişmeye çalışırken bu hataları alıyorsunuz..
    wp_get_attachment_image_src fonksiyonu, aradığınız dosya URL'sini bulamadığında false döndürür. Bu nedenle, get_term_meta işlevinin döndürdüğü sonucu kontrol etmeniz ve ardından wp_get_attachment_image_src işlevinin sonucunu kullanmadan önce boş olup olmadığını kontrol etmeniz gerekir.

    Şöyle deneyin:
    function ekleme_mt(){
        if(is_category()){
            $term = get_queried_object();
            $term_image_id = get_term_meta(get_queried_object_id(), 'dosya-url', true);
            if (!empty($term_image_id)) {
                $term_image = wp_get_attachment_image_src($term_image_id, 'full')[0];
                $term_bilgi = wp_get_attachment_metadata($term_image_id);
                $post_id = $term_image_id;
                echo '<meta property="og:image" content="'.$term_image.'" />
                      <meta property="og:image:type" content="'.$term_bilgi["sizes"]["medium"]["mime-type"].'" />
                      <meta property="og:image:width" content="'.$term_bilgi["width"].'" />
                      <meta property="og:image:height" content="'.$term_bilgi["height"].'" />
                      <meta property="og:image:alt" content="'.get_the_excerpt($post_id).'" />
                ';
            }
        }
    }
    add_action('wp_head', 'ekleme_mt',9);
    Teşekkürler hocam, uyguladım hata gitti
  • 14-05-2023, 01:01:45
    #7
    zentamedia adlı üyeden alıntı: mesajı görüntüle
    Muhtemelen $term_image değişkeni false olarak ayarlanmış, dolayısıyla bir diziye erişmeye çalışırken bu hataları alıyorsunuz..
    wp_get_attachment_image_src fonksiyonu, aradığınız dosya URL'sini bulamadığında false döndürür. Bu nedenle, get_term_meta işlevinin döndürdüğü sonucu kontrol etmeniz ve ardından wp_get_attachment_image_src işlevinin sonucunu kullanmadan önce boş olup olmadığını kontrol etmeniz gerekir.

    Şöyle deneyin:
    function ekleme_mt(){
        if(is_category()){
            $term = get_queried_object();
            $term_image_id = get_term_meta(get_queried_object_id(), 'dosya-url', true);
            if (!empty($term_image_id)) {
                $term_image = wp_get_attachment_image_src($term_image_id, 'full')[0];
                $term_bilgi = wp_get_attachment_metadata($term_image_id);
                $post_id = $term_image_id;
                echo '<meta property="og:image" content="'.$term_image.'" />
                      <meta property="og:image:type" content="'.$term_bilgi["sizes"]["medium"]["mime-type"].'" />
                      <meta property="og:image:width" content="'.$term_bilgi["width"].'" />
                      <meta property="og:image:height" content="'.$term_bilgi["height"].'" />
                      <meta property="og:image:alt" content="'.get_the_excerpt($post_id).'" />
                ';
            }
        }
    }
    add_action('wp_head', 'ekleme_mt',9);
    Hocam resimli kategorilerde böyle hata veriyor şimdi de:

    167 nolu satır: <meta property="og:image:type" content="'.$term_bilgi["sizes"]["medium"]["mime-type"].'" />

    Warning: Undefined array key "medium" in /var/www/...php on line 167

    Warning: Trying to access array offset on value of type null in /var/www/...php on line 167
  • 14-05-2023, 01:05:35
    #8
    medium şeklindeki boyutunu oluşturmuyor olabilir, medium yerine thumbnail ya da full kullanmayı deneyebilirsiniz.