2016-12-17 54 views
0

我使用husamrayan開發的WordPress插件icon box
在我的使用案例中,我製作了類別,因此每個類別都包含少量圖標,每個圖標都有自己的標題;我可以通過acf(高級自定義字段)關於它的ID,名稱,金額等信息獲得類別。
但是我怎樣才能獲得屬於該類別的每個圖標的標題?檢索Wordpress圖標框標題(插件)

例如,在圖片:
如何,我能得到的圖標冠軍屬於shop_cate3 因爲我已經得到shop_cate3信息從get_field('fields_name');

enter image description here

ACF ------加上信息-------
我使用插件'acf'和'圖標框'。
這裏我如何設置iconbox作爲分類和自定義字段名稱'shop_service',我可以定義與其中一個類別相關的帖子並讓該類別包含一些圖標。

enter image description here

然後在single.php,我通過ACF功能檢索自定義字段中的數據:
$terms = get_field('shop_service'); 然後,如果我分析裏面$terms數據將是:

{ 
"term_id":31, 
"name":"shop_cate_3", 
"slug":"%e5%ba%97%e9%9d%a23", 
"term_group":0, 
"term_taxonomy_id":31, 
"taxonomy":"icoonboxcategory", 
"description":"", 
"parent":0, 
"count":4, 
"filter":"raw" 
} 

但我不能檢索圖標與此類別相關。

+1

你想獲得標題? – vel

+0

我想在另一個插件php中獲取它,將數據放到我的對象中。但是我會在post,single.php中測試。 – jojomango

+0

我們可以看到代碼片段嗎? stackoverflow.com/help/how-to-ask –

回答

0

對於ppl遇到同樣的問題,我發送郵件給作者,他說現在不是插件功能,但我可以在inc/shortcodes.php中檢查它。
當年這裏是解決方案:

$shop_service = get_field('shop_service'); 

    $category = $shop_service->term_id; 

    $args = array ('post_type' => 'icoonbox', 
        'posts_per_page' => $num, 
        'orderby' => $orderby, 
        'order' => $order, 
        'suppress_filters' => true); 

    if($category > 0) { 
     $args['tax_query'] = array(array('taxonomy' => 'icoonboxcategory','field' => 'id','terms' => intval($category))); 
    } 

    $icon_titles = array(); 
    $icoonbox_query = new WP_Query($args); 
    if ($icoonbox_query->have_posts()) { 
     $posts = $icoonbox_query->posts; 
     foreach ($posts as $key => $item) { 
      $pair = array(); 
      $pair['title'] = $item->post_title; 
      $pair['id'] = $item->ID; 
      array_push($icon_titles, $pair); 
      } 
    } 

上面添加到您想要的圖標ID和標題的代碼,所有你需要的將是$ icon_titles的數據!
對不起,也許代碼有不必要的部分,因爲我沒有真正掌握php語言。