It happens when the foreach()
is fed with an invalid entry, because there is no term returned. To prevent this, wrap your loop inside a conditional:
// Get the terms( categories ) for the portfolio item
$terms = get_the_terms( $post_item->ID, 'portfolio_categories' );
if(is_array($terms) || is_object($terms)){
foreach( $terms as $term ) {
// some code here
}
}
Now, the loop will only run only the post has some terms.
Related Posts:
- Handling duplicates with wp_insert_term()
- Get PHP Fatal error on globalized $wpdb: Call to a member function insert() on a non-object- I have no clue. What to do?
- get_term_link() returns correct – But illogical error-messages disturb
- PHP Warning: Attempt to read property “term_id” on bool
- What might cause “junk after document element” error?
- Trying to display terms from custom taxonomy within function
- Cannot access non-wordpress subdirectories as wordpress overrides them with a 404 error
- Show all terms of a custom taxonomy?
- Showing errors with $wpdb update
- Change login error messages
- WP_DEBUG is not set, but I’m still getting warnings
- Inserting terms in an Hierarchical Taxonomy
- How to disable the fatal error (WSOD) protection?
- Should I use spl_autoload_register() in my plugin?
- WP-CLI – Selecting PHP version
- error_log() output for print_r() appearing on page
- Unable to locate WordPress Content directory (wp-content)
- When to use Exceptions vs Error Objects vs just plain false/null
- Could not create directory /wp-content/upgrade/
- Getting the warning: Missing argument 2 for manage_posts_custom_column()?
- What log files does a WordPress installation write to?
- How to display admin error notice if settings saved succesfully?
- HTTPS leads to Sorry, you are not allowed to access this page
- How to fix “There has been a critical error on your website. Please check your site admin email inbox for instructions”?
- Notice: Undefined index: host in /var/www/html/wp-includes/canonical.php on line 445
- What is the best way to monitor PHP functions/executions?
- Notice: Use of undefined constant SCRIPT_DEBUG
- Notice: Constant WP_POST_REVISIONS already defined
- Uncaught ReferenceError:switchEditors is not defined
- Hide php Notices in Dashboard
- How to stop certain warning logging in error.log?
- WordPress Redirecting to wp-admin/install.php
- PHP Catchable fatal error: Object of class WP_Error could not be converted to string
- Upgrading PHP version results in “Use of undefined constant WP_CONTENT_DIR” warning?
- Error 404 Page Not Found When Updating a Post or Page
- Debug mode shows Strict Standards
- How to use WP_Error $data argument?
- Is it possible to disable caching of an option when using w3 total cache?
- WSOD but WP_DEBUG not giving any errors
- Why on Earth am I getting “undefined_index” errors?
- Showing error “Function create_function() is deprecated”
- wp_set_object_terms and arrays
- WordPress “Link has expired” error on updating posts
- strange characters in wordpress website displayed for visitors [closed]
- PHP Deprecated: Non-static method should not be called statically
- Debugging ‘Object of class WP_Query could not be converted to int’ error
- How to fix ob_end_flush() error?
- When does remove_filter not work?
- wp_remote_get() not retrieving pages properly
- error_log over 70GB. How to stop this? [closed]
- $wpdb->insert Database Error Duplicate Entry Error Logging
- foreach error on false boolean from get_terms
- Update wordpress fail – There has been a critical error on your website
- How to find objects by terms
- This webpage is not available ERR_NAME_NOT_RESOLVED
- Displaying oEmbed errors?
- Getting headers already sent error from plugin
- “Apache HTTP Service has stopped working” with WP Query in WordPress 2.9.2
- Error 310 too many redirects after switching domains
- How do I set up Debugging?
- get_terms return errors
- Display certain amount of posts on taxonomy archive page
- Plugin.php: PHP Notice: Undefined offset: 0 in
- get_the_content if it contains multiple lines it results in SyntaxError
- Get used terms by an author as array of strings
- Error Logs to Diagnose Error 500 in LAMP
- Add image only in first post
- category not display in word press grammatically
- Error messages when adding code to function.php or trying to delete inactive plugin files
- “Notice: Undefined index:” error when adding new content?
- 418 header status, I’m a teapot [closed]
- Showing “ Notice: Undefined variable:” and “ Notice: Trying to get property of non-object”
- How to get the term before the last from a custom taxonomy?
- List all categories but exclude current post category on single post page
- Publishing Time – WordPress Plain White Screen with No Error
- Object of class WP_Error could not be converted to string
- Notice: Constant already defined in wp-config.php on (non-existent) line?
- How to resolve error “Cookies are blocked due to unexpected output.”?
- error_log is not working as expected in functions.php file
- New WordPress Error Message – Not seen this before
- Does wordpress have an error log?
- Enable errors PHP WordPress 5.2
- WP_DISABLE_FATAL_ERROR_HANDLER vs WP_DEBUG ? What to use and when to use to see errors?
- Recommend a guide to catching plugin errors, please?
- “Can’t use function return value in write context” error
- Get all taxonomies for all post types
- How do I get taxonomy terms by ID in a specific order
- Fatal error: Call to undefined function wpsc_cart_item_count()
- How to handle core code throwing notice on valid input?
- Getting Warnings & Notices from Fresh WordPress 3.1.2 install
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- WP_Query use for a filter with multiple Taxonomies and Terms
- Error when requesting password reset email – wp authentication
- Call to undefined function get_header() in index.php
- How can I create a custom page for this error?
- “Notice: Undefined variable: content” is showing [closed]
- List Category Posts plugin upgrade fails with fatal error
- Sodium compat error
- Append a term to WooCommerce product existing product category terms
- Fatal error: require(): Failed opening required ‘WP_DIRwp-blog-header.php’