Jump to content

Help With Function If Statement


eddioot

Recommended Posts

Hi all,

 

i am fairly new with php and i am running into a problem with a php function. It is very basic but i've got something wrong here.

 

It is a function in wordpress that needs to analyze the post and extract the category. For every category another value needs to be returned. My code is:

 

function postimage($post_id){
$category = get_the_category( $post_id );
$id = $category[0]->cat_ID;


if ( $id = 45 ){
 $link = 'This is category 45';
}
else {
 $link = 'This is not category 45 ';
}


return $link;
}

 

There are 2 strange things happening:

 

1. The first statement is always true. Even if the category id is not 45 it still returns the first $link.

2. If i return the variable $id after the if statement it returns als 45. If i do it without the if statement it returns correct.

 

The 2 problems are obviously related but i don't understand what i'm doing wrong. Please help :tease-03:

Link to comment
https://forums.phpfreaks.com/topic/271190-help-with-function-if-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.