I'm attempting to then add logic to some wordpress template. I wish to develop a simple if conditional that will see if a flexible equals 26. The variable "$value" must contain additional hidden figures, because after i echo this content... 26 seems prior to the echo string values which should appear first. Therefore, the if-condition doesn't work either. What's happening here and just how can one repair it?


$value=the_ID();   // a wordpress function which contains the id of the current page/post.
echo "value=(" . $value . ")";



The reason being the_ID() is really a template function: it only echo's the ID it does not give it back. You need to be utilising get_the_ID() rather.

the_ID() is not coming back something, it's printing it. This is exactly why you cannot assign it to that particular variable.

If you're able to edit the function get it return the worthiness (although that could break other areas from the application which are by using their function). Or capture it such as this:

$value = ob_get_clean();
echo "value=(" . $value . ")";

What goes on whenever you comment the echo? Does the 26 still appear? If that's the case then your function does echo it rather than coming back it.

Use var_dump to print the variable's content for debugging:

var_dump( $value );

Appears like the_ID() echoes the ID itself.

You can either do that:

echo "value=(".the_ID().")";

or if you want to assign value to make use of later inside your script, this:

echo "value=($value)";

You say you want to make use of an if within the script, to ensure that perform similarly -

if(get_the_ID()==26){/*do whatever*/}

You can obviously also employ $value==26 should you designated it earlier.

As numerous people claim that the_ID() perform the echoing. You will find a couple of steps you can take here.

First, find out if WordPress includes a function to come back the ID rather than printing it (Personally, i have no idea).

Second, you might just arrange the code to allow it print as you desire ... such as this

echo "value=(" . the_ID() . ")";


echo "value=("; the_ID(); echo ")";

Third, If you want to be inside a variable, you might capture the echo output. Such as this

$Value = ob_get_contents();
echo $Value;

Hope this can help.

I wager the function you're calling echoes the amount 26..

so.. value will really = null..

therefore the_ID() most likely is really a function such as this:

function the_ID(){
    $id = 26;
    echo $id;

ie: it doesn't return anything, it echoes the end result. (should you traul through teh wordpress source code you can most likely fuind what is happening... and discover in which theIdentification() is actulaly getting ethe page id from.

Used to do a fast explore the wordpress instructions:

Note: This function shows the ID of the publish, to come back the ID use get_the_ID(). Usage

<?php the_ID(); ?>

which means you are utilizing the incorrect function

use get_the_ID() not the_ID()

the_ID(); //prints teh page id
$value=get_the_ID(); //returns the page_id