Strictly by what I see in your code: you are trying to unset
incorrectly, unset
works by means of an array key and you are using $term_id
which is a value. You need to find the index in the array for that $term_id
:
function wpfs_save_tax( $term_id ) {
$featured_tax = get_option( '_featured_tax' );
if ( empty( $featured_tax ) ) {
$featured_tax = array();
}
if ( isset( $_POST['wpfs_tax'] ) ) {
if ( ! in_array( $term_id, $featured_tax ) ) {
$featured_tax[] = $term_id;
}
} else {
if ( in_array( $term_id, $featured_tax ) ) {
unset( $featured_tax[array_search( $term_id, $featured_tax )] );
}
}
update_option( '_featured_tax', $featured_tax );
}
Related Posts:
- How do I get the current edit page ID in the admin?
- Order posts (across the whole site) by metadata date
- Disable visual editor on one specific page
- How to display random users with avatars
- Apply custom role capabilities to administrator (without plugin)
- Can the wp-plugins (Must Use Plugins) URL be targeted for use in functions.php?
- In a WordPress plugin, how do you output HTML code inside the DOM header? [closed]
- Different ‘WP_CONTENT_URL’ for different subsites in Multisite setup?
- Linking thumbnail to full size image
- is_front_page not working in functions.php
- VERY new to coding – keep breaking site trying to add to functions.php
- Display WordPress Search
- Preferred Use of home_url()?
- Functions.php reverted to new one
- Where does function_exists() look to decide whether a function exists? [closed]
- Get page slug and assign a variable within functions.php
- Clean-up script tags
- Make “sidebar template” the default template for new pages
- Custom roles can’t access to wp-admin
- How to specify which Gutenberg blocks are available in the editor for a page template
- Refactor create_function
- Logic to Print/echo a css class only for 1st post and ignore all post after 1st? [closed]
- Attach parent category template to all subcategories
- How to insert a text in all pages and posts before or after specific places?
- Add class or ID to any WordPress function
- How to filter out shortcode when displaying the_excerpt() in the loop?
- Remove Font-Awesome MaxCDN Link & Load Locally
- How to remove howdy dropdown menu content
- Change Admin Bar “Visit Site” URL
- exclude a category from a search on a specific page
- How do I pass arguments for multiple functions hooked to a single action?
- Stop turning small dashes into longer ones
- How to get specified parent page title in my function
- Execute function after a post has been published
- Last updated date function
- Possible to display shortcode based on the category?
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- How to set default archive image without overriding first attached image? [closed]
- Toggle User Roles with button
- Passing a variable via wp_head and then calling it on the page
- Load Woocommerce and WordPress Functions Outside
- How to make custom column Admin>Users sortable?
- Theme functions.php file auto delete everyday [closed]
- How to know which ajax file or function is called for action
- How to filter $content in shortcode function
- Generating dynamic css into custom file [closed]
- watermarking gallery items
- Difficulty with PHP function that displays a post’s format in WordPress
- WordPress Shortcode function display outside of widget
- Get rid of the widget Item Class=”widget-item”
- Function coding error concatenating quotes I think
- Need print logo without any ID & class
- Reset postdata not working on WP_Query in functions.php
- Filter nav menu items HTML tags and wrap inner text with span
- Change menu based on page template via functions.php
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Using Static HTML instead of the `home_url()` WP function
- How to append classname to body tag if guest user
- Why is it so hard to add a class to the tag in the sidebar widget?
- Parent theme styles overriding child theme CSS [closed]
- Adding theme option values as custom body class
- How to add a new image size and apply it to posts only?
- Can I include a custom PHP function in a WordPress function?
- Removing parent theme CSS without editing parent theme
- Showing user profile data on front-end
- How to register a menu based on a ACF condition
- Breaking up multiple words and inserting an image after first word
- Why is this function crashing my wordpress installation? [closed]
- colorbox not loading in
- Can I use ‘Featured Image’ as a hero image and a thumbnail?
- How to Override Page Template if URL matches query?
- Save_post – Warning: Cannot modify header information
- Woocommerce Display Discount On cart
- Modify content inside post before first publish
- Pass an argument into a function to extract from array
- How to offset main query without affecting other queries and backend
- ACF Date Form in Custom Admin Field
- how to remove a tag in the_category function
- Execute jQuery with custom event listener after successfully add an item to the cart
- Copying a widget class to functions.php results on a blank page
- WordPress undefined function error on using add_action() in functions.php
- How to create admin ajax function for my contact form
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Changing the register url is not working
- Newest comments first not working
- Pass arguments to function class with do_action()
- how to display featured image for single post for a specific category
- Database Query not working
- Can I use a function to return HTML and the result of another function?
- save_post hook – headers already sent?
- How to use WP_rewrite?
- Wp get archive only text not link
- can not call functions in function.php
- Custom shortcode not being included in content paragraph [duplicate]
- Display post_meta-by_key on product catalogue
- What are the parameters are used in add_action and filters?
- Which template file to edit to edit homepage in Mystile [closed]
- Does functions.php apply to every page?
- Creating mixture of shortcodes to use in the visual/text editor
- woocommerce_sort_product_tabs() expects an array