I’m struggling to compare two php variables to display or not display some text depending if the variables match or not. This is what I have:
<?php $link = the_permalink();?>
<?php $portfolioloop = new WP_Query( array( 'post_type' => 'news' ) ); ?>
<?php while ( $portfolioloop->have_posts() ) : $portfolioloop->the_post(); ?>
<?php while(the_repeater_field('featured_companies')): ?>
<?php $company = the_sub_field('featured_company'); ?>
<?php if ($link == $company) { ?>
show news articles
<?php } else { ?>
don't show news articles
<?php } ?>
<?php endwhile; ?>
<?php endwhile; // end of the loop. ?>
I want to compare $link and $company and if they match then do the stuff within the if. Where am I going wrong?
I’m using the http://www.advancedcustomfields.com plugin in WordPress if that helps.
UPDATE:
Firstly forgot to mention that the two variables are urls. At the moment it’s echoing out 2 urls that are the same on the page I want, but it’s also echoing out “show news articles” when the 2 urls don’t match.
Underneath the twitter profile – http://www.mediwales.com/v3/members/mediwales/ shows the same two urls. But when you goto this page http://www.mediwales.com/v3/members/3m/ it shows two different urls yet shows “show news articles”.
Just solved it: