leasben Posted May 3, 2023 Share Posted May 3, 2023 Hi team, please assist in resolving the following issue above, below is my code: ); $projects_query = new WP_Query( $projects_args ); if ( $projects_query ->have_posts() ) { echo '<h3>Projects</h3>'; while ( $projects_query->have_posts() ) { $projects_query->the_post(); $term_id = get_field( 'technology' ); $term = get_term( $term_id, 'technologies' ); $icon = $term->slug; ?> <div class="slider_btn <?php echo $icon; ?> offices"> <a href="<?php echo get_the_permalink(); ?>"><span class="eng"><?php echo get_the_title(); ?> </span><span class="fr"><?php the_field('french_title');?></span></a> </div> <?php } } endif; Quote Link to comment https://forums.phpfreaks.com/topic/316249-warning-undefined-property-wp_errorslug/ Share on other sites More sharing options...
cyberRobot Posted May 3, 2023 Share Posted May 3, 2023 Have you tried outputting the variables to see if they contain expected values? Based on the error message in the title, it sounds like $term contains an error object (WP_Error) instead of a term (WP_Term).https://developer.wordpress.org/reference/functions/get_term/#return Quote Link to comment https://forums.phpfreaks.com/topic/316249-warning-undefined-property-wp_errorslug/#findComment-1607975 Share on other sites More sharing options...
leasben Posted May 3, 2023 Author Share Posted May 3, 2023 I have modified the code to look like this but I get an error has occurred on your site, learn more about WP troubleshooting if ( $projects_query->have_posts() ) { echo '<h3>Projects</h3>'; while ( $projects_query->have_posts() ) { $projects_query->the_post(); $term_id = get_field( 'technology' ); $term = get_term( $term_id, 'technologies' ); if ( ! is_wp_error( $term ) && isset( $term->slug ) ) { $icon = $term->slug; } else { $icon $icon = 'default-icon'; } wp_reset_postdata(); } Quote Link to comment https://forums.phpfreaks.com/topic/316249-warning-undefined-property-wp_errorslug/#findComment-1607979 Share on other sites More sharing options...
cyberRobot Posted May 3, 2023 Share Posted May 3, 2023 The error is likely caused by the following line: $icon $icon = 'default-icon'; Note the duplicate $icon. Quote Link to comment https://forums.phpfreaks.com/topic/316249-warning-undefined-property-wp_errorslug/#findComment-1607980 Share on other sites More sharing options...
leasben Posted May 3, 2023 Author Share Posted May 3, 2023 5 hours ago, cyberRobot said: The error is likely caused by the following line: $icon $icon = 'default-icon'; Oh thats a typo i made when I was typing in the code. Quote Link to comment https://forums.phpfreaks.com/topic/316249-warning-undefined-property-wp_errorslug/#findComment-1607999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.