Jump to content

Recommended Posts

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;

Link to comment
https://forums.phpfreaks.com/topic/316249-warning-undefined-property-wp_errorslug/
Share on other sites

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

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();

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.