Question

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?

Was it helpful?

Solution

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 );
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top