Get data terms taxonomy acf field như thế nào?

Thảo luận trong 'Mã nguồn mở Wordpress' bắt đầu bởi seolagi, 13/6/24.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,032
    Đã được thích:
    81
    Điểm thành tích:
    48
    HI mình có cái cái chuyên mục taxonomy terms sử dụng acf field (Advanced Custom Fields) để tạo dữ liệu, cột dữ liệu là id_video.
    Giờ mình chuyền giá trị vào hết rồi gọi nó ra thì không lầy được, giúp mình sửa code với, cảm ơn
    Mã:
    $terms_top =  get_terms( array(
      'taxonomy' => 'video',
      'order' => 'DECS',
      'posts_per_page' => 1,
      'orderby'=>'date',
      'meta_key'      => 'gim_len_dau',
      'meta_value'    => '2:Yes',
      'hide_empty'=> false
    ));
    if(isset($terms_top) && count($terms_top) > 0)
    {
      foreach ( $terms_top as $term ) {
        $contents = get_field('id_video', $term->term_id); 
      }
    }
    
    • Mình làm vậy ở các bài viết thì vẫn lấy được bình thường, mà sao vào chuyên mục category thì không được, cảm ơn
     
    Cảm ơn đã xem bài:

    Get data terms taxonomy acf field như thế nào?

  2. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,931
    Đã được thích:
    1,203
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Chuyên mục ngoài bài viết post, page thì phải truyền vào tham số nhận diện nữa thì mới lấy được.

    Như trên sửa lại code thành như sau sẽ lầy được nhé:
    Mã:
    $terms_top =  get_terms( array(
      'taxonomy' => 'video',
      'order' => 'DECS',
      'posts_per_page' => 1,
      'orderby'=>'date',
      'meta_key'      => 'gim_len_dau',
      'meta_value'    => '2:Yes',
      'hide_empty'=> false
    ));
    if(isset($terms_top) && count($terms_top) > 0)
    {
      foreach ( $terms_top as $term ) {
           $contents = get_field('id_video', $term->taxonomy . '_' . $term->term_id);
      }
    }
    
    • Thêm cái: $term->taxonomy . '_' để lấy được giá trị nhận diện filed của taxonomy sẽ lấy được đúng ngay.