You’re getting the Fatal Error because array_diff() is comparing the WP_Term objects in your array to a string, and it can’t do that. Here’s one way to fix that:
Replace
$topic = array_diff($topic, ["expired"]);
with:
$my_topic = array();
foreach ( $topic as $term ) {
if ( 'expired' !== $term->slug ) {
// Adds $term to my topic if it's not 'expired'.
$my_topic[] = $term;
}
}
// $my_topic is the new $topic.
$topic = $my_topic;
Related Posts:
- Sorting list of sites from multisite network using wp_get_sites
- How to store the_title() into a variable to reutrn the value, not just echo it
- How to update single value in multi dimensional Post Meta?
- Need to get specific data from array
- Create an array from an array
- WP_User_Query order by meta_key that is an array
- How do I dynamically generate args for wp_query?
- Must Use Plugin Causing Query Error
- ‘orderby’ => ‘rand’ alternative for better performance?
- How to convert objects into arrays
- Parsing php string in jquery [closed]
- Admin Options page. Save as Array
- PHP get the first post separately from array returned by wpdb->get_results()
- Working with query_posts ( arrays and query strings)
- how can i show only the parents in owl-carousel?
- How can I add multiple ‘tax_query’ arrays via a loop?
- How to properly loop through these external URLs to get them into the sitemap using this hook
- Call global variable array() in woocommerce child/template
- Populate dropdown with Child Pages based on Parent Page chosen
- PHP Array Returning [object Object]. Tried existing answers results with no luck
- foreach loop still echoes array
- Advanced Custom Fields – display label and value only if value entered
- Grouping posts by a custom meta value
- wp_force_remove_style’ not found
- How can I access string value in an array?
- Filtering a function’ output for a new continued function
- Error while setting role
- How to say if meta_value is greater than 0 in an array?
- How to use two meta_compare in an array?
- Loop over Array and get the distinct ids
- How to access or parse key/values that have “string”
- If Array Values Match Another Array’s Values, Then
- Remove empty terms from array, sort alphabetically, update back to repeating field
- Only show first image in foreach loop
- Conditional multidimensional arrays and array_map
- How can I get all values from my array in a loop in php? [closed]
- Get all posts as an array ID => Name
- I’m unable to call img path using single quotes in an array?
- Filter by field with array value in ACF on WP REST API
- extract serialized array to use for wp-query
- Get the id of all images in a post
- Output category list inside array
- Multidimensional Array
- Separate array output into a
- Only load certain artists on this page
- add the value of a variable returned in a while loop [closed]
- Update value of a associative array with update_post_meta
- How to make sure relative URL works when site is not on root domain?
- Get URI from PodPress using PHP
- How To Pass Array To get_the_category_by_ID() and Get An Array Back?
- using images in next/previous_post_link [closed]
- Finding and removing duplicates within WP Arrays
- Add custom fields from different posts
- MySQL Query Returns Array () In Shortcode
- Convert a column of a table containing an Array as response in HTML
- Create an array with all the links of the years’ archive (of a custom post type)
- Display just one post from a loop of 5 posts?
- Redux option doensn’t seem when include from functions.php
- in_array not working on dev server but works on localhost
- how to separate an array into different arrays and save them into db?
- How to insert multiple rows and columns in database using array
- Display one random image from Media Library
- How to display MySQL table data which is stored as an array?
- ACF – Get ID of relationship field in flexible content
- Replace an array (with identical values) with another array in the_content
- Show the subcategory name based on current product
- get_category_parents to array
- Notice : Array to string conversion on array_intersect user meta
- get_users when from meta key that has serialized values
- How can get all users by current user meta (array)?
- Display posts using post ID’s in an array
- How can i iterate through this shortcode array?
- Display a single row from nested array of custom field data
- Add custom filter to register data in array
- Page returning ID from array, how to return the correct values for post in acf wordpress
- Reformat data within a nested array
- Create Customization Controls from Array
- Non-array argument in array_merge()-function [closed]
- Display a post based on its metabox selection
- Unserializeing multiple column values that are stored in one database results variable
- How to get values from wordpress listings and use them in javascript array?
- Repeatable field within repeatable group of fields
- wp_get_archive for category returning different URLs on different but similar sites
- !in_array doesnt recognize category
- get_permalink returning first letter
- Showing all post from all post type in admin backstage
- How to set if meta_value is lower < than other meta_value in a get_posts array?
- How to print array of specific item
- Populate checkboxes from array
- Use php array outside his function
- Retrieve Array from within Array [closed]
- save array of objects with update_option
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- How to group by column a and sum column b and c in a php array
- Replace block content with an array
- Adding date and time to the same request
- How to pass php array to external js file in WordPress
- Get check box values inside array for use in posting form data
- Warning: Array to string conversion in /css/base.php on line 500 [closed]
- Inserting more than one array into same row