• 13-10-2023, 19:03:24
    #1
    /** * Function to automatically update the product focus keyword with the product category */
    function update_product_focus_keywords()
    { $products = get_posts(array( 'posts_per_page' => 100, 'post_type' => 'product'  )); foreach ($products as $p) { $keywords = []; if (get_the_terms($p->ID, 'product_cat')) { foreach(get_the_terms($p->ID, 'product_cat') as $term) { $keywords[] = strtolower($term->name); } update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords))); } }
    }
    add_action('init', 'update_product_focus_keywords');
    bilen bir arkadaş kodu ayarlayabilir mi? istediğim şey rank math üzerinde kategori ağacındaki en alt kategorinin odak anahtar kelime olarak ayarlanması bu kod en baştaki kategoriyi ayarlıyor

    örneğin; notebook çantaları yeirne aksesuarları baz alıyor ücretli ya da ücretsiz yardım alabilirim
  • Kabul Edilen Cevap
    • Aradığınız kod:
      /** * Function to automatically update the product focus keyword with the product category */
      function update_product_focus_keywords()
      { $products = get_posts(array( 'posts_per_page' => 100, 'post_type' => 'product' , 'orderby ' => 'ID', 'order' => 'DESC')); foreach ($products as $p) { $keywords = []; if (get_the_terms($p->ID, 'product_cat')) { foreach(get_the_terms($p->ID, 'product_cat') as $term) { $keywords[] = strtolower($term->name); } update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords))); } }
      }
      add_action('init', 'update_product_focus_keywords');
      veya aşağıdaki kod gibi array_reverse komutunu kullanabilirsiniz. (Post sıralamasına göre keyword de sorun yaşar mısınız kontrol etmeniz lazım alttaki kod için)
      /** * Function to automatically update the product focus keyword with the product category */
      function update_product_focus_keywords()
      { $products = get_posts(array( 'posts_per_page' => 100, 'post_type' => 'product'  )); foreach ($products as $p) { $keywords = []; if (get_the_terms($p->ID, 'product_cat')) { foreach(get_the_terms($p->ID, 'product_cat') as $term) { $keywords[] = strtolower($term->name); } update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique(array_reverse($keywords)))); } }
      }
      add_action('init', 'update_product_focus_keywords');
  • 13-10-2023, 20:01:24
    #2
    Takip
  • 14-10-2023, 06:20:47
    #3
    Bu cevap, moderatörlerimiz tarafından kabul edilebilir bir cevap olarak işaretlendi.
    Aradığınız kod:
    /** * Function to automatically update the product focus keyword with the product category */
    function update_product_focus_keywords()
    { $products = get_posts(array( 'posts_per_page' => 100, 'post_type' => 'product' , 'orderby ' => 'ID', 'order' => 'DESC')); foreach ($products as $p) { $keywords = []; if (get_the_terms($p->ID, 'product_cat')) { foreach(get_the_terms($p->ID, 'product_cat') as $term) { $keywords[] = strtolower($term->name); } update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords))); } }
    }
    add_action('init', 'update_product_focus_keywords');
    veya aşağıdaki kod gibi array_reverse komutunu kullanabilirsiniz. (Post sıralamasına göre keyword de sorun yaşar mısınız kontrol etmeniz lazım alttaki kod için)
    /** * Function to automatically update the product focus keyword with the product category */
    function update_product_focus_keywords()
    { $products = get_posts(array( 'posts_per_page' => 100, 'post_type' => 'product'  )); foreach ($products as $p) { $keywords = []; if (get_the_terms($p->ID, 'product_cat')) { foreach(get_the_terms($p->ID, 'product_cat') as $term) { $keywords[] = strtolower($term->name); } update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique(array_reverse($keywords)))); } }
    }
    add_action('init', 'update_product_focus_keywords');