get_post_custom
-
Hello again
On some homepage items of my theme, the publisher will be able to change the background colour of the div to make the info stand out.
To achieve this, I created a custom field for the posts named “change_colour”.
In the loop, I test the custom field, which is either empty or contains the word “black”:
<?php [bla bla] the_post(); $MAMA = get_post_custom(); $DADA = $MAMA['change_colour']; if ($DADA='black'): [ CSS CHANGE ] ; [endif etc]Hmm. My PHP works but results are not as expected. Everything turns black. Doesn’t work.
I php-[echo]ed the variable to check: it just says “Array”.
Damn. What am I missing ?
-
Try using something like:
<?php $color = get_post_meta($post->ID, 'change_colour', true); if( $color == 'black' ) : [CSS CHANGE] endif;?>Thanks. It did the job nicely.
However, may I say the codex on that matter is far too vague and far too unclear for a non specialist like me.
Compare :
• get_post_custom :
« returns a multidimensional array with all custom fields of a particular post or page »
• get_post_meta :
« returns the values of the custom fields with the specified key from the specified post.»I don’t know if WordPress has a commercial branch and uses the tremendous success of the free software to make business (and if it’s not, it should), but after browsing through the codex for a few days/weeks now, it could definitely be made simpler AND/OR more complete, to appeal to the larger number.
Why not hire a written communication debugger and planner ? I am free for hire !
WordPress commercial activities don’t extend beyond some aspects of wordpress.com and automattic.com. Generally it’s based open open source, community-developed tools and resources.
If you could help with the Codex and you’d be willing to volunteer a little time, I’m sure your experience would be more than welcome. There is a Documentation mailing list that you might be interested in. Other than that, all it takes is to create a Codex account, read through the Wiki documentation and join in.
The topic ‘get_post_custom’ is closed to new replies.