Help me fix PHP code that's causing Critical Error on my WordPress site

DerangedWolf

Elite Member
Jr. VIP
Joined
Apr 30, 2018
Messages
1,924
Reaction score
1,512
I don't know PHP. I found some codes on StackOverflow and rest is suggested by other BHW members in my last thread. Finally, I came up with this:
PHP:
<?php
$ori = the_terms('origin');
if (!empty($ori)) :
    ?>
    <div class="tax"><p class="origin tax-label">Origin</p><p class="tax-link tax-label"><?php the_terms( $post->ID, 'origin', '' ); ?></p></div>
<?php
   endif;
}
?>

It saves perfectly from the WordPress dashboard but shows a critical error on the front end. I would really appreciate if someone helps me with fixing the code :)

@Reti @kaudo @codemaker, please help me again if you have a minute or two :)
 
Go to your wp-config.php file and enable debug mode.

Use this code:
PHP:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
/*
If the website is live, you might want to set this to false.
Setting it to true will make the errors and warnings display on the frontend.
If you set this to false, no errors/warnings will show on the frontend but the will be loged in /wp-content/debug.log
*/
define('WP_DEBUG_DISPLAY', true);

It might be there already but set to false. So set it to true.

That code will make WordPress show the exact error message in the frontend.

Now refresh the page and paste the errors here.
 
And also check your email, WP probably sent you some details.
 
also pls try to remove the closing curly bracket "}" that is right after the "endif".
I can´t see opening one nowhere in your code...
 
the_terms() takes 2 required arguments ($post_id and $taxonomy), you don't have second. And you have an unnecessary 3rd in 2nd call.
Also, rendering 2 paragraphs like that won't give you the nices looking result in this case.
get_the_terms() is the right function, not the_terms().

What's wrong with our solutions from yesterday?
 
What's wrong with our solutions from yesterday?

They were perfect, but I want to hide the label if the taxonomy is empty. I modified the code and it worked. Thanks again
 
Back
Top