• If I use the below, I get my standard category ID by slug.

    <?php
    $catId = get_term_by( 'slug', 'test', 'category' );
    $catId = $catId->term_id;
    print_r($catId)
    ?>

    But What I need is the ID of my custom taxonomy categories for my custom post_type. How would I do that?

    Custom taxonomy is:
    taxonomy = event-categories
    post_type = event

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try this:

    <?php
    $catId = get_term_by( 'slug', 'event-cat-slug', 'event-categories' );
    $catId = $catId->term_id;
    print_r($catId)
    ?>

    If you need to get the posts in your post type that have a particular Event Category, something like this:

    <?php
    $query_args = array(
        'post_type' => 'event',
        'tax_query' => array(
            array(
                'taxonomy' => 'event-categories',
    	    'field' => 'slug',
    	    'terms' => 'event-cat-slug'
            )
        )
    );
    $query = new WP_Query( $query_args );
    $posts = $query->posts;
    ?>
    Thread Starter rontarson

    (@rontarson)

    Yeah I tried

    <?php
    $catId = get_term_by( 'slug', 'event-cat-slug', 'event-categories' );
    $catId = $catId->term_id;
    print_r($catId)
    ?>

    before and wasn’t able to get it to pull the taxonomy ID. You had the same thought process I did. I can’t seem to figure this out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying Custom Taxonomy Category Data’ is closed to new replies.