How to target custom taxonomy in WordPress

I have a plugin that creates custom taxonomy categories for showing portfolio. On hovering Edit categories on admin panel, i see link like :

localhost/site/wp-admin/edit-tags.php?action=edit&taxonomy=mg_item_categories&tag_id=13&post_type=mg_items

Read More

What i want to do is add some CSS (a ribbon image), if product displays from a specific category. For example if products from category ‘new’ are displayed, it all shows “New Ribbon Image” So i am confused how can i target taxonomy? Any idea from the above link?

Should i use is_post_type, is_taxonomy or anything else that can help targetting taxonomy ID 13.

Here is the function that makes this taxonomy :

function register_cpt_mg_item() {
$labels = array( 
        'name' => _x( 'Item Categories', 'mg_item_categories' ),
        'singular_name' => _x( 'Item Category', 'mg_item_categories' ),
        'search_items' => _x( 'Search Item Categories', 'mg_item_categories' ),
        'popular_items' => NULL,
        'all_items' => _x( 'All Item Categories', 'mg_item_categories' ),
        'parent_item' => _x( 'Parent Item Category', 'mg_item_categories' ),
        'parent_item_colon' => _x( 'Parent Item Category:', 'mg_item_categories' ),
        'edit_item' => _x( 'Edit Item Category', 'mg_item_categories' ),
        'update_item' => _x( 'Update Item Category', 'mg_item_categories' ),
        'add_new_item' => _x( 'Add New Item Category', 'mg_item_categories' ),
        'new_item_name' => _x( 'New Item Category', 'mg_item_categories' ),
        'separate_items_with_commas' => _x( 'Separate item categories with commas', 'mg_item_categories' ),
        'add_or_remove_items' => _x( 'Add or remove Item Categories', 'mg_item_categories' ),
        'choose_from_most_used' => _x( 'Choose from most used Item Categories', 'mg_item_categories' ),
        'menu_name' => _x( 'Item Categories', 'mg_item_categories' ),
    );

    register_taxonomy( 'mg_item_categories', array('mg_items'), $args );
}

Related posts

Leave a Reply

1 comment

  1. using this code get your '13' category taxonomy post :

    <?php
    $args = array(
        'tax_query' => array(
            array(
            'taxonomy' => 'mg_item_categories',
            'field' => 'id',
            'terms' => '13'
                )),
    
    'post_type'=>'mg_items',
    'order'=>'ASC',
    'posts_per_page'=>-1
    );
    
    query_posts($args);
    while ( have_posts() ) : the_post(); 
    
    $image_id = get_post_thumbnail_id(); 
    $image_url = wp_get_attachment_image_src($image_id,'full');   
    ?>
        <h2> <?php the_title(); ?></h2>
        <?php the_content(); ?>
    
        <?php if ( has_post_thumbnail() ) { ?>
        <a href="<?php the_permalink(); ?>"><img src="<?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" /></a>
        <?php } ?>
    
        <?php   
        endwhile; 
        wp_reset_query();
    ?>