Php If statements in WP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Php If statements in WP

Post by aravona »

I've trawled the Wordpress forums but there isn't really an answer to my question.

I've got an If statement which uses an Id which you can call with wpsc_vargrp_id(); however it seems to want to ignore the if statement.

I echo'd the wpsc_vargrp_id and got 1, 2 and 4. Its the group using id 4 which I want to display differently with the If statement.

So I added:

Code: Select all

if (wpsc_vargrp_id() == '4') { 
Display vargrp 4 
}
else {
display all other vargrps
}
But it just ignored the if statement and just uses the else.

Since I can't get an answer on the WP forums I was hoping someone here could help :)

Regards,

Aravona
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Php If statements in WP

Post by greyhoundcode »

If that's your actual code up there then the problem is basically a syntax error.
aravona wrote:

Code: Select all

if (wpsc_vargrp_id() == '4') { 
    Display vargrp 4 // This isn't PHP
}
else {
    display all other vargrps // Nor is this
}
Try something like this perhaps:

Code: Select all

$result = wpsc_vargrp_id();

if ($result == 4) {
    echo '4';
}
else {
    echo $result;
}
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Php If statements in WP

Post by s992 »

You said that you "echo'd the wpsc_vargrp_id and got 1, 2 and 4." Were all of these numbers returned in an array?
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Php If statements in WP

Post by greyhoundcode »

aravona wrote:I've trawled the Wordpress forums but there isn't really an answer to my question.
Doesn't this relate to the plugin made by Instinct? Maybe they've got specific support forums/IRC channels.
Post Reply