I have some trouble making work a conditional inside a Function.
check this out:
I'm using this function:
function get_spec_1(){
$desc1 = get_post_meta( get_the_ID(), 'eco_mb_tp_1', true!= "" );
if(!empty ($desc1)){
foreach ( $desc1 as $d1 ){
$code = "
<dl>
<dt class='bullet6-top'>General</dt>
<dd>
<ul>
<li>$d1</li>
</ul>
</dd>
</dl>
";
echo $code;
}
}
}
But this function causes this:
<dl>
<dt class='bullet6-top'>Generales</dt>
<dd>
<ul>
<li>$metabox_cloned_value_1</li>
</ul>
</dd>
</dl>
<dl>
<dt class='bullet6-top'>Generales</dt>
<dd>
<ul>
<li>$metabox_cloned_value_2</li>
</ul>
</dd>
</dl>
But what I'm trying to achieve is this:
<dl>
<dt class='bullet6-top'>Generales</dt>
<dd>
<ul>
<li>$metabox_cloned_value_1</li>
<li>$metabox_cloned_value_2</li>
</ul>
</dd>
</dl>
And if there is no existing data.
then the entire <dl>
will not show.
How can I obtain this result?
thanks
get_post_meta()
in a very strange way. What result do you expect? An array of all meta data with this key or just the last value?get_post_meta()
not to a simpletrue
orfalse
? What is the expected result?