WordPress has the wp_list_pluck
function, which can be helpful here. We can make an array of just term IDs from the array of objects like:
$term_ids = wp_list_pluck( $subcat_terms, 'term_id' );
Then we can check in_array
:
$this_id = 42;
if( in_array( $this_id, $term_ids ) ){ // do something }
Related Posts:
- get a simple array of all of the term names that exist in all taxonomies
- How to store the_title() into a variable to reutrn the value, not just echo it
- wp_set_object_terms and arrays
- category not display in word press grammatically
- Need to get specific data from array
- Create an array from an array
- Problems with function on function.php
- get_the_terms – only top level
- Query all posts of a custom taxonomy term
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Populate dropdown with Child Pages based on Parent Page chosen
- foreach loop still echoes array
- Checking array against author id in loop
- Alter required message using comment form api
- meaning of (array)function()
- wp_force_remove_style’ not found
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- How can I access string value in an array?
- Filtering a function’ output for a new continued function
- Limit Taxonomy Output in Conditional Statement
- Isotope Drop Down Categories Filter Function
- How to use array in function to get only value I want
- Warning: in_array() null given in PHP function
- Hierarchical taxonomy list with modificated term links
- Loop over Array and get the distinct ids
- If Array Values Match Another Array’s Values, Then
- Only load certain artists on this page
- How to make sure relative URL works when site is not on root domain?
- Custom functions for string data calculations
- Store custom field’s multiple values in one user meta key
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Display posts using post ID’s in an array
- Page returning ID from array, how to return the correct values for post in acf wordpress
- Display a post based on its metabox selection
- ISOTOPE – Missing/Invalid Arguement Get Terms
- Showing all post from all post type in admin backstage
- Custom WordPress Function – Adding items from Foreach Loop into an array and Updating Field based on array of IDs (ACF + WooCommerce)
- WordPress different custom tag being displayed in on tag list
- Replace block content with an array
- Cleaning up WordPress to improve performance?
- How can I modify the permalink via a filter?
- Metabox repeating fields – radio buttons not saving correctly
- How can merge two arrays values in one array and save in database
- How to use WordPress (PHP) functions in AngularJS partials files?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- List all categories but exclude current post category on single post page
- Can an array be used as a meta_query value?
- Nested shortCode functions in the functions.php file
- Show only IF not Google bot [closed]
- How the functions in WP are called in tags
- How to speed up admin-ajax.php in wordpress
- My Own layout in WooCommerce pages [closed]
- Woocommerce – remove product from category
- Differences when using the the_time and the_date functions
- How to style options page in dashboard?
- How to access global variable $menu inside a class function
- Why ajax doesn’t work on certain wordpress hooks?
- Print last modified date only on posts
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- Modify function to print tags/categories/exclude tags/categories/ number of posts
- Search not showing all results
- Make Current/Active Page Number a Link (WP_LINK_PAGES)
- How to make modifications only to certain elements of an HTML string on the server-side?
- Custom Pagination is Broken
- Sidebar not appearing in footer, but it appears everywhere else!
- How can I hook into the wp_mail function used by BackWPup?
- List post by title length
- how to enqueque code in a php file from functions.php
- Convert all uploaded PNG files to PNG-8 format
- Uses for function: wp_update_user
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Display logged in user name and lastname on page
- How to output the taxonomies that are assigned to each custom post?
- Exclude category from function – PHP
- Hide a specific category title from displaying on site
- Replace an array (with identical values) with another array in the_content
- Handling form actions in WordPress
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Shortcode’s output to use as other shortcode’s parameter
- Populate Posts based on category selected using AJAX that means without page refresh
- Displaying POST content with HTML tags and all
- PHP script to redirect traffic based on website accessed
- How to remove title tag with this filter
- Why transition_post_type hook is called twice for the same post?
- Can’t get_users info by using json_encode
- What is wrong in this code?
- Retrieving specific images from Media Library
- Can’t put a hyperlink on Featured Post’s Image
- Permission error on plugin save
- Removing all my hardcoded URLs with get_site_url()
- Display default WordPress login/registration form into a modal window
- Highlight main menu when on specific posts or pages
- Incomplete term slugs output from a foreach loop with get_the_terms
- Pull GET parameter from URL in functions.php
- Adding Gravity Form With if(is_page) Is Not Working
- Woocommerce – Shipping tax class based on cart items not using the highest tax available
- Alternative to php echo within code
- Add multiple HTML attributes to an Elementor button
- /page/2/ redirect to 404
- Adding date and time to the same request