0
votes

I'm using WordPress plugin icon box developed by husamrayan.
In my use case I make categories so every category contains few icons and every icon has its own title; and I can get the category in post with acf (advanced custom field) about its id, name, amount... etc.
But how could I get every icons' title belonging to the category?

For example, in the picture:
How could I get titles of icons belonging to shop_cate3 as I already get shop_cate3 info from acf by get_field('fields_name');

enter image description here

-------plus info-------
I use both plugins 'acf' and 'icon box'.
Here how do I setup iconbox as a taxonomy and custom field name 'shop_service', which I could define post related to one of the categories and have the category contain some icons.

enter image description here

Then in single.php, I retrieve custom field data by acf function:
$terms = get_field('shop_service'); Then if I parse the data inside $terms it would be:

{
"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"
}

But I cannot retrieve icons related to this category.

1
where you want to get the title?. - Vel
I want to get it in another plugin php, to put the data to my object. But I will test in post, single.php. - jojomango
Can we see the code snippet? stackoverflow.com/help/how-to-ask - T-Heron
it's little bit complicated, let me add some description on question... - jojomango

1 Answers

0
votes

For ppl encounter same issue, I sent mail to author, he said it's not a feature in plugin now, but I could check it in inc/shortcodes.php.
Then here is the solution:

    $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);
            }
    }

Add the code above to where you want icons id and titles, all the data you need would be in $icon_titles!
Sorry maybe the code has unnecessary part due to I don't really master php language.