• When this code runs it prints a word called “MyCategory”

    <?php the_taxonomies(array('before'=>'<span class="categories" style="font-size:16px;font-weight:bold;">','sep'=>'</span><span class="tags">','after'=>'</span>')); ?>

    I want to get this word “MyCategory” in to a variable called $my_variable
    How to do this?

    I tried this way. But its not successful.

    <?php $my_variable = the_taxonomies(array(‘before’=>'<span class=”categories” style=”font-size:16px;font-weight:bold;”>’,’sep’=>'</span><span class=”tags”>’,’after’=>'</span>’)); ?>

    <?php echo $my_variable ?> // NOT success

    Need help!!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You are missing a semi colon at the end of your echo. I just ran this and it works fine for me:

    <?php $test_variable = the_taxonomies(array('before'=>'<span class="categories" style="font-size:16px;font-weight:bold;">','sep'=>'</span><span class="tags">','after'=>'</span>'));
        echo $test_variable; ?>
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You don’t need a semicolon there if you’re closing off PHP

    EDITED: Inaccurate answer

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Try taking this bit of your code away:

    <?php echo $test_variable; ?>

    And seeing the output

    That’s the problem.

    My apologies, didn’t entirely think that one through. What you could do is use get_the_taxonomies instead and extract the returned array as you see fit.

    Thread Starter zerandib1

    (@zerandib1)

    i want to compare the variables

    if(strcmp(the_taxonomies(array('before'=>'<span class="categories" style="font-size:16px;font-weight:bold;">','sep'=>'</span><span class="tags">','after'=>'</span>')) , "MyCategory")
    {
       echo "OK";
    }
    else{
      echo "NOT OK";
    }

    Since the words are not matching, it always shows “NOT OK”

    How can i get the output “OK”?

    please let me know how to use this get_the_taxonomies with this example

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to get the value into a variable?’ is closed to new replies.