skip to Main Content

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


  1. $tag_id = get_queried_object()->term_id;

    Login or Signup to reply.
  2. 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:

    function overwrite_ratings_category( $term_id ) {
        update_field( 'field_630dbc7cf3fdd', '432', 'category_' . $term_id );
    }
    add_action( 'edit_term', 'overwrite_ratings_category', 10, 1 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search