0

Can I access the current category of a category feed with the rss2_head hook to add for example itunes tags?

Lets say I have wordpress.com/catx/feed I want to get acf field elements associated with this specific category.

Here is what I am trying to accomplish:

function itunes_head() {
        $category = get_the_category();
        $categories = get_category();
        global $post;
        var_dump($categories);
        echo print_r($post);
        echo $categories;
        echo $category;
}
add_filter( 'rss2_head', 'itunes_head' );

I am assuming that I somehow can retrieve the catx category here?

1 Answer 1

1

I think you can just fetch it from the global query using get_queried_object:

function itunes_head() {
    if ( is_category() ) {
        $category = get_queried_object();

        if ( isset( $category ) ) {
            $acf_category = 'category_' . $category->term_id;

            $field = get_field( 'my_category_field', $acf_category );
        }
    }
}
1
  • Thanks, get_queried_object() was what I was looking for! Commented May 13, 2021 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.