I’m trying to output the if statement, but instead the else statement shows. I have created a page using WordPress and assigned this template to the page. I’m trying to show product image and content if number of products is > 0, which it is. But instead it shows the else statement. Can someone please help?
<?php
/*
Template Name: Product Single Template
*/
$productsPermalink = pods_var('last', 'url');
$singleProductPod = pods('products', $productsPermalink);
$numProducts = $singleProductPod->total();
?>
<?php get_header(); ?>
<section>
<?php if($numProducts > 0):
?>
<h1><?php echo $singleProductPod->field('name'); ?></h1>
<div class="instructor single">
<img src="<?php echo $singleProductPod->field('image.guid') ?>" alt="<?php echo $singleProductPod->field('name')?>">
<p><?php echo $singleProductPod->field('content')?></p>
</div>
<?php else: ?>
<h3>There is no such product: <?php echo $productsPermalink; ?>, please select another product</h3>
<?php endif; ?>
It probably shows the if statement because in the line
<?php if($numProducts > 0):
you have the condition that if the value$numProducts
is less than0
it should instead execute theelse
clause.Try and use
die (var_dump ($numProducts));
to see the output and find out what really is going on.While you’re at it try using
var_dump
on$singleProductPod->total();
as well.Maybe you’ll find out that the values of these variables isn’t quite what you thought it would be.