What you need is pretty much straight out of the Codex:
$terms = get_the_terms( $post->ID, 'on-draught' );
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
$draught_links[] = $term->name;
}
get_the_terms()
can return a term object, false
, or a WP_Error
object. You are checking for neither the false
nor the error object. That is what this conditional does:
if ( $terms && ! is_wp_error( $terms ) )
Use it instead of if(is_array($terms)){
Related Posts:
- How to get post or page excerpt using post_excerpt
- Page template gives ‘Parse error: syntax error’ when used, but no error found!
- The entire content of my WordPress page has disappeared
- Redirect “Sorry, you are not allowed to access this page.” to Home
- Page not found error when adding text `2 = 2 ^ 1` to the page
- Created php page in wordpress – Error Page can not be reached
- Suddenly forbidden 403 error on some pages
- Special Character Appearing in my WordPress Pages Content
- Published pages missing
- WordPress slow pages/post, hangs and white text
- PHP warning $post->ID is null
- All pages duplicated like a mirror with critical errors
- Can’t create new pages in wordpress
- Why does updating the front page give a 403, but no other page?
- Multiple alias for single page
- More Fields Required For Password protect page
- How to make my category archive behave like a page
- Page template no longer exists – metaboxes won’t save
- A static page view call every custom page templates
- Add external css to Contact Page
- Wrapping images in tags based on size
- page-name.php doesn’t execute on custom template
- Layout Builder.
- New user Registration data imported into Page
- Getting error when using wp_insert_post()
- Edit custom HTML page from WP admin dashboard
- Could be a namespace conflict (?) with login form and register form on the same page
- Removing Parent Page URL While Keeping the Navigation Intact
- The concept of non-blog content
- Loading Multiple Comments Pages via Ajax?
- Change base URL of pages created by certain users
- Error: options page not found
- Organizing Your Pages
- Add categories and posts to page hierarchy
- get_pages() as per custom menu order
- Create a page that’s to not be indexed or accessible via slug
- How to retrieve attachments from child pages of a specific Page?
- Dynamic Landing Page
- Creating a dashboard menu page similar to the “Pages” page
- Headers already sent in Pluggable.php / homepage and wp-login error
- Updated WordPress, now getting errors on site
- Role can edit just one page [closed]
- Pass data from one page to anothe file/page in wordpress
- Get the ID of the direct parent page
- Custom page template for multiple pages
- get_the_title() gets printed out twice
- How do I find PHP file that contains content of my page?
- External stylesheet per page
- IF user is logged in only show certain page
- Which is the correct way to conditionally enqueue a CSS file?
- How do I Name a WP page in the New(ish) Block Editor?
- My custom template page not loading content inside it?
- “Undefined index” error when saving empty array with checkboxes
- No Appearance panel is shown
- Remove Content edit box from ALL pages (not posts)
- How to detect if is_404() or is_page() or etc…? [closed]
- Can a user find a child page?
- WordPress page content outside WordPress
- What is full URL for a post?
- How to control who can view certain pages in BuddyPress? [closed]
- Using the_excerpt() on a page
- Display child pages in sidebar of parent page in wordpress
- What is a subpage in WordPress?
- how to edit source code of specific page in wordpress?
- Inject class in body when particular page template is used
- How to add prefix slug in static wordpress page?
- Get the Current Page Slug-Name
- Get $post Object from another page
- Edit Parent page drop menu when creating a page
- Get parent of current page
- Use .php file as page instead of wordpress page & template file?
- Use WordPress function in php file
- Display child pages in a parent page? [closed]
- Redirect page to default subpage
- how to avoid the character conversion of WordPress pages?
- How to edit a HTML list in WordPress?
- How to list a page tree?
- How to use is_admin in page content?
- How to create a page and display only the posts with a specific custom field value?
- Is it possible to activate page template without manually selecting it in wp-admin?
- Excerpt Now Showing on the Post Page
- How can I use “getarchives_where” to get monthly archives for static pages?
- Admin taking a very long time to load
- check first and last child pages wordpress
- Remove problem PHP code entered into footer via Theme
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- How to check if the current page is at a specified path in the URL?
- how to display sidebar on pages in wordpress
- Attachment pages stealing page slugs
- WordPress pages creation work distribution & then combining – Localhost XAMPP
- hard coded html / php pages on local host directory don’t show up in WP dashboard
- All Pages visible on the Frontpage
- How to select a specific page
- Hide page templates without using ‘unset’
- Custom page with queries returns 404
- WordPress Site Page Exists but Error 404
- Show About and Contact Us page when they’re clicked in the top menu.
- Where can i make an html change to a specific page [closed]
- How to capture GET argument on static page
- Adding a Calculator to a WordPress Page