Home Forums General Issues Get category slug name out of Taxonomy field


Get category slug name out of Taxonomy field

  • I m trying to get the category slug name out of a Taxonomy ACF field “Category” and return its value inside an array which will help me display Latest Posts from selected Category.

    $catName = get_field('latest_news_category');
                $args = array(
                    'post_type'         => array('post'),
                    'post_status'       => array('publish'),
                    'category_name'     => $catName,
                    'posts_per_page'    => '3',
                    'orderby'           => 'date',
                    'order'             => 'DESC',
  • The field you have set up is returning the term ID only. To get the slug then you either need to return term object or you need to get the term object yourself.

    The first thing you need to do is figure out if you want ACF to return IDs or change it to term object.

    If you use ID then to get the term name you need to first use

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.