If we refer to the documentation, we see that get_the_terms
returns an array, false, or a WP_Error object. So in our code we’ll add a check if $collection_values
exists (it’s not false), and it’s not an error, then we’ll know it has to be an array, and it’s safe to run a foreach
loop on it.
$collection_values = get_the_terms( $product->id, 'pa_collection');
if ( $collection_values && ! is_wp_error( $collection_values ) ){
foreach ($collection_values as $collection_value){
echo '<h2 class="collection_title"><a href="'.get_term_link($collection_value->slug, $collection_value->taxonomy).'">'.$collection_value->name.'</a></h2>';
}
}
Related Posts:
- How to check if woocommerce is activated in theme
- Detect a focus on wp_editor
- Failed media upload: “The uploaded file was only partially uploaded.”
- retrieve thumbnail from post ID of best selling product in category
- Display a selected custom product option in WooCommerce cart
- Changing user_nicename
- How to create different menu’s for not logged in visitors and for logged in members?
- Utilize WP-CLI from inside WordPress, not SSH
- Using a function written in my functions.php file within the header.php file
- How to link to a custom .php page in my folder
- How to execute a simple php script in WP (I don’t think wp_enque_script applies here)
- Front end submit form with jquery form plugin
- Sortable admin column for one meta key with three possible meta values
- WP_Query meta_query results date by date
- Rewrite sub folder dynamically with country code in WordPress using PHP
- Use WordPress’ URL rewrite engine
- Display all categories including sub categories
- wp nav menu: add attributes to menu items [duplicate]
- Advanced Custom Fields: Post Object – Not returning data [closed]
- Is there a way to get 3+ dimensional array from a single MySql command
- Admin Options page. Save as Array
- AJAX request status 200 but no actual “response”
- Delete a WordPress transient from a shortcode on Page/Post update
- How to enable Zend Optimiser+ with Batcache
- Getting the author name on author archive page
- how to add three default images to wordpress?
- Create own WordPress shortcode gallery
- Is sanitize_title_with_dashes formatting function too liberal (in terms of accepted characters)?
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- How do I exclude recent post from recent post php widget
- dynamic dependent select dropdown
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Hide menu items in WordPress
- Best way to schedule daily change in CSS parameter
- wp-comments-post.php file returns a blank page
- wp_mail file attachment not being placed in upload folder?
- WordPress Child Themes
- Email address not displaying where I expect it to
- need to insert php code in path Get Template Part [closed]
- Set Cache-Control header for 301 redirects
- Automatically set all tags to have a height of 0 if there is no content inside the tag [closed]
- if statement with is_active_sidebar()
- WordPress template page name displayed on screen
- How to add API security keys into JS of wordpress securely
- Link blogname and blogdescription to the Options Framework
- Why does the post_type_link hook everything twice?
- Adding conditional text to a PHP Shortcode Template
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- Warning: in_array() null given in PHP function
- wp_nav_menu not working correctly in my underscores theme
- use loop to return blog details
- PHP error when using newer PHP versions
- Environment to do updates to legacy (4.7) version of WP while staying on php 5.6?
- How can I count ACF sub_field with a certain value
- WP_Query with AJAX returning empty array
- How to add post meta in while loop?
- Adding function to child theme’s function.php
- How to set a featured image (thumbnail) with PHP?
- Output custom text field as unordered list
- Using Conditionals when homepage is a page and blog is /blog
- WP Container Displaying Only on First Page of Archive
- Hook on file upload
- Contact Form 7 WordPress, checking a few fields, if empty then invalid
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Update Images after edit via php
- Drop down question
- How to move a post from one category to another
- WordPress add custom search
- custom mailchimp form using HTTP API
- How to get the url of the entry in which an image belongs
- How to override theme’s public static function inside of a trait?
- pass datetime using wp_localize_script to frontend from settings page
- Advanced Custom Forms PHP formatting for do_shortcode
- Infinite loop when logging out using custom login form
- add custom metabox to media library custom widget
- add_action in wp_head accessible from class
- Changing default WPMU emails to be send thorugh Campaign Monitor Transactional emails
- Can’t add to time? [closed]
- Getting page / post URL on publish and / or update
- AJAX Filter WHILE Loop not working WordPress
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- How to add style in functions.php depending on conditions?
- Weird Behaviour: Not all WordPress Posts appearing
- Extra text in the sidebar for 1 menu item and his sub-menu items?
- Dynamic form variables for post meta
- allow previews outside wordpress folder (Outsourcing WP previews)
- PHP Widget and do_shortcode
- Date when the custom field was added
- How do I call comments_template(); from a plugin file?
- Add ASC / DESC to custom post columns
- How to return a Boolean for a page that is a subpage thru its name?
- session_start(): Cannot find save handler ‘mm’ – session startup failed in /sites
- Can you not edit the HTML and PHP of your WordPress without paying?
- $_html is empty when var dumped
- Event plugin problem any one solve .? [duplicate]
- how to Show BEFORE TEXT before in wordpress get_comment_meta [closed]
- Force array to be a string [closed]
- Adding jquery using php function