• 03-10-2020, 00:50:27
    #1
    Üyeliği durduruldu
    Merhaba arkadaşlar,

    Ben wordpress veritabanından bir sitenin açıklama kısmına nitelikleri çekiyorum. Ancak burada 3 adet çekilmesini istemediğim nitelik mevcut ( çünü onları başka yere çekiyorum ) bu 3 id yi çekmeyi nasıl engelleyebilirim ? yani 8, 9 , 5 , bu id ler gelmesin isttiyorum onun dışında ki bütün idler gelsin.

    Kodum bu şeikilde

    add_action( 'woocommerce_shop_loop_item_title', 'custom_attributes_display', 20 );
    function custom_attributes_display(){
    global $product;
    
    if( ! $product->is_type( 'simple' ) ) return;
    
    $loop_count = 0;
    
    echo '<div>';
        
        
    
    
    $attributes_taxonomy = $product->get_attributes();
    
    foreach( $attributes_taxonomy as $taxonomy => $attribute ) {
    
    $attribute_terms = wp_get_post_terms( get_the_id(), $taxonomy, array( 'fields' => 'names' ) );
    $terms_string = implode( ',', $attribute_terms );
    
    if( count( $attribute_terms ) > 0 ){ 
    echo '<p style="border:solid">'.$attribute->get_name().' : '.$terms_string.'</p>';
    
    $attr_count = count( $attributes_taxonomy );
    $loop_count++;
    }
    }
    
    echo '</div>';
    }
  • 03-10-2020, 00:59:38
    #2
    https://wordpress.stackexchange.com/...get-post-terms

    yukarıda çözüm var , slug kısmını id olarak güncelleyerek yapabilirsiniz.

    @Proffice;
  • 03-10-2020, 01:00:21
    #3
    Üyeliği durduruldu
    Bilisimworld adlı üyeden alıntı: mesajı görüntüle
    https://wordpress.stackexchange.com/...get-post-terms

    yukarıda çözüm var , slug kısmını id olarak güncelleyerek yapabilirsiniz.

    @Proffice;
    id olarak gösterirsem bu sefer o id leri çekicek ama ben 3 id yi çekmesin istiyorum
  • 03-10-2020, 01:04:29
    #4
    Proffice adlı üyeden alıntı: mesajı görüntüle
    id olarak gösterirsem bu sefer o id leri çekicek ama ben 3 id yi çekmesin istiyorum
    $terms = wp_list_filter($terms, array('slug'=>'myslug'),'NOT');


    Buradaki NOT hariç tutmak için kullanılıyor, dahil etmek için değil.
  • 03-10-2020, 01:05:49
    #5
    Üyeliği durduruldu
    Bilisimworld adlı üyeden alıntı: mesajı görüntüle
    $terms = wp_list_filter($terms, array('slug'=>'myslug'),'NOT');


    Buradaki NOT hariç tutmak için kullanılıyor, dahil etmek için değil.
    mantığı anlamak için soruyorum hocam böyle mi yapmam gerek ?

    add_action( 'woocommerce_shop_loop_item_title', 'custom_attributes_display', 20 );
    function custom_attributes_display(){
    global $product;
    
    // Just for simple products
    if( ! $product->is_type( 'simple' ) ) return;
    
    $loop_count = 0;
    
    echo '<div>';
        
        
    $terms = wp_get_post_terms( $post->ID, 'wedding_cat');
    $terms = wp_list_filter($terms, array('slug'=>'myslug'),'88');
    
    // Get the attributes taxonomy slugs (Updated and dynamic now)
    $terms = $attributes_taxonomy;
    $attributes_taxonomy = $product->get_attributes();
    // OR set an indexed array of taxonomy slug (key) and name (value) to chose which ones, like:
    // $attributes_taxonomy = array('pa_nopeus' => 'Nopeus', 'pa_liito' => 'Liito, 'pa_vakaus' => 'Vaukaus' );
    
    foreach( $attributes_taxonomy as $taxonomy => $attribute ) {
    
    // Getting the term names of an attribute (set in a coma separated string if many values)
    $attribute_terms = wp_get_post_terms( get_the_id(), $taxonomy, array( 'fields' => 'names' ) );
    $terms_string = implode( ',', $attribute_terms );
    
    // Displays only if attribute exist for the product
    if( count( $attribute_terms ) > 0 ){ // Updated
    echo '<p style="border:solid">'.$attribute->get_name().' : '.$terms_string.'</p>';
    
    // Separating each number by a " | " (Updated and dynamic now)
    $attr_count = count( $attributes_taxonomy );
    $loop_count++;
    }
    }
    
    echo '</div>';
    }
  • 03-10-2020, 01:24:43
    #6
    $terms = wp_list_filter( $terms, [ 'term_id' => 88], 'NOT' );

    böyle denermisin.
    Proffice adlı üyeden alıntı: mesajı görüntüle
    mantığı anlamak için soruyorum hocam böyle mi yapmam gerek ?

    add_action( 'woocommerce_shop_loop_item_title', 'custom_attributes_display', 20 );
    function custom_attributes_display(){
    global $product;
    
    // Just for simple products
    if( ! $product->is_type( 'simple' ) ) return;
    
    $loop_count = 0;
    
    echo '<div>';
        
        
    $terms = wp_get_post_terms( $post->ID, 'wedding_cat');
    $terms = wp_list_filter($terms, array('slug'=>'myslug'),'88');
    
    // Get the attributes taxonomy slugs (Updated and dynamic now)
    $terms = $attributes_taxonomy;
    $attributes_taxonomy = $product->get_attributes();
    // OR set an indexed array of taxonomy slug (key) and name (value) to chose which ones, like:
    // $attributes_taxonomy = array('pa_nopeus' => 'Nopeus', 'pa_liito' => 'Liito, 'pa_vakaus' => 'Vaukaus' );
    
    foreach( $attributes_taxonomy as $taxonomy => $attribute ) {
    
    // Getting the term names of an attribute (set in a coma separated string if many values)
    $attribute_terms = wp_get_post_terms( get_the_id(), $taxonomy, array( 'fields' => 'names' ) );
    $terms_string = implode( ',', $attribute_terms );
    
    // Displays only if attribute exist for the product
    if( count( $attribute_terms ) > 0 ){ // Updated
    echo '<p style="border:solid">'.$attribute->get_name().' : '.$terms_string.'</p>';
    
    // Separating each number by a " | " (Updated and dynamic now)
    $attr_count = count( $attributes_taxonomy );
    $loop_count++;
    }
    }
    
    echo '</div>';
    }
  • 03-10-2020, 01:28:11
    #7
    Üyeliği durduruldu
    Bilisimworld adlı üyeden alıntı: mesajı görüntüle
    $terms = wp_list_filter( $terms, [ 'term_id' => 88], 'NOT' );

    böyle denermisin.
    yok hocam silmedi yukarıda ki koda göre $termsi değiştirmemiz gerekmez mi
  • 03-10-2020, 01:32:43
    #8
    bu şekildede olabilir. olmuyorsa bu olay üzerinden araştırabilirsiniz hocam .

    add_action( 'woocommerce_shop_loop_item_title', 'custom_attributes_display', 20 );
    function custom_attributes_display(){
    global $product;
    *
    // Just for simple products
    if( ! $product->is_type( 'simple' ) ) return;
    *
    $loop_count = 0;
    *
    echo '<div>';
    *****
    *****
    $terms = wp_get_post_terms( $post->ID, 'wedding_cat');
    $terms = wp_list_filter($terms, array('term_id'=>88),'NOT');
    *
    // Get the attributes taxonomy slugs (Updated and dynamic now)
    $terms = $attributes_taxonomy;
    $attributes_taxonomy = $product->get_attributes();
    // OR set an indexed array of taxonomy slug (key) and name (value) to chose which ones, like:
    // $attributes_taxonomy = array('pa_nopeus' => 'Nopeus', 'pa_liito' => 'Liito, 'pa_vakaus' => 'Vaukaus' );
    *
    foreach( $attributes_taxonomy as $taxonomy => $attribute ) {
    *
    // Getting the term names of an attribute (set in a coma separated string if many values)
    $attribute_terms = wp_get_post_terms( get_the_id(), $taxonomy, array( 'fields' => 'names' ) );
    $terms_string = implode( ',', $attribute_terms );
    *
    // Displays only if attribute exist for the product
    if( count( $attribute_terms ) > 0 ){ // Updated
    echo '<p style="border:solid">'.$attribute->get_name().' : '.$terms_string.'</p>';
    *
    // Separating each number by a " | " (Updated and dynamic now)
    $attr_count = count( $attributes_taxonomy );
    $loop_count++;
    }
    }
    *
    echo '</div>';
    }
    Proffice adlı üyeden alıntı: mesajı görüntüle
    yok hocam silmedi yukarıda ki koda göre $termsi değiştirmemiz gerekmez mi
  • 03-10-2020, 01:36:35
    #9
    Üyeliği durduruldu
    olmadi sanırım term id değilde attributes_taxonomy id bulmam lazım