Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7556929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:59:33+00:00 2026-05-30T11:59:33+00:00

I’m struggling to compare two php variables to display or not display some text

  • 0

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”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:59:34+00:00Added an answer on May 30, 2026 at 11:59 am

    Just solved it:

    <h2>Latest News</h2>    
    <?php $link = get_the_title(); ?>
    <?php $portfolioloop = new WP_Query( array( 'post_type' => 'news' ) ); ?>
    <?php while ( $portfolioloop->have_posts() ) : $portfolioloop->the_post(); ?>  
        <?php $post_link = get_post_permalink(); ?>                        
            <?php  if (get_field('featured_companies') != "") { ?>
                <?php foreach(get_field('featured_companies') as $post): ?>
                    <?php $company = get_the_title($post_object->ID); ?>
                    <?php if ($company == $link) { ?>
                        <a href="<?php echo $post_link; ?>">News item 1</a>
                    <?php } ?> 
                <?php endforeach;?>
            <?php } ?>
    <?php endwhile; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.