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 8421069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:02:28+00:00 2026-06-10T03:02:28+00:00

<?php // SEARCH TAGS FOR A SPECIFIC TAG $tags = CollectionAttributeKey::getByHandle(‘recipe_tags’); // attribute handle

  • 0
<?php // SEARCH TAGS FOR A SPECIFIC TAG
  $tags = CollectionAttributeKey::getByHandle('recipe_tags'); // attribute handle of tags to search
  $tagToFind = 'Videos'; // declare the specific tag to find
  $selectedTags = array($page->getAttribute($tags->getAttributeKeyHandle())); // get tags associated with each page and put them in an array

  foreach ($selectedTags as $tag) { // output tags separately

    echo $tag; // ECHO TEST - check that individual tags associated with each page are outputting correctly

    if ($tag == $tagToFind) { // if $tag is equal to $tagToFind
      echo ' Found';
    } else {
      echo ' Not found';
      }
  }
?>

echo $tag; outputs the list of tags associated with each page so I’m pretty sure the issue is how I’m checking if ‘Videos’ is in the list of tags.

The above outputs the following list: Breakfast Brunch Budget Meal Easy Lunch Quick Meals Supper Vegetarian Videos and Not found even though Videos is in the list.

I’ve also tried using in_array to look for ‘Videos’ like this:

if (in_array($tagToFind, $selectedTags, true)) { // search the array for $tagToFind - true = strict
  echo ' Found';
} else { 
    echo ' Not found';
  }

But get the same result – I’m new to php so sorry if this is easy.

Any help would be much appreciated.

Cheers

  • 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-06-10T03:02:29+00:00Added an answer on June 10, 2026 at 3:02 am
    $page->getAttribute($tags->getAttributeKeyHandle()) 
    

    seems to return a string.

    In that case

    $selectedTags = array($page->getAttribute($tags->getAttributeKeyHandle())); 
    

    makes no sense – you get an array containing one long string.

    What you want to to is:

    $selectedTags = $page->getAttribute($tags->getAttributeKeyHandle());

    if(stristr($selectedTags, $tagToFind)){
      // do something
    }
    else{
      // do something else
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to modify a php search script so that it can handle multiple
Possible Duplicate: PHP MySQL multiple search query using option / select HTML form tags
How to test my php search engine project ? Client side Minimum browser requirement
I have a PHP search script which I've altered slightly and works well for
I need to create a php search function for names and need to change
Given: Url - http://www.contoso.com/search.php?q= {param} returns: -html- --body- {...} ---div id='foo'- ----div id='page1'/- ----div
Is it possible to use php to search a string for a file path
I have 2 files, main.html and search.php . Within the main.html page, there is
I want to search a php file to find all calls to a functions
I've built a search index using the PHP Zend Framework Search (based on Lucene).

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.