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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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 );
}
}
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0