I’have some problem with my WordPress functions.php script.
When I go to edit Category of Post, I have URL:
/wp-admin/term.php?taxonomy=category&tag_ID=3&post_type=post&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dcategory
I need a function to update the field in category with ID from URL.
function overwrite_ratings_category(){
update_field('field_630dbc7cf3fdd', '432', 'category_'.$_GET['tag_ID']);
}
add_action('edit_term','overwrite_ratings_category');
When I use number (e.g. 3) instead $_GET[‘tag_ID’] function works fine. But it’s not working with $_GET[‘tag_ID’].
Is there any other way to get the ID of the currently edited category?
2
Answers
$tag_id = get_queried_object()->term_id;
Since you’re using edit_term action, it gives your term id as the first param, you can use this param and do your job like the below code: