• Resolved Anna Johansson

    (@vintagemaniac)


    Having an odd problem…

    Using this code to fetch a custom meta value only when one is present almost works for me:

    if (get_post_custom()) {
    $quote = get_post_meta($post->ID, 'quote', true);
    echo "<div class=\"quote\">$quote</div>";
     }


    The almost is this:

    If a post has a tag, but not a custom meta value (the $quote) it shows the div container. If a post doesn’t have tags and no meta value no div shows up (as I want it).

    As long as the $quote is defined it doesn’t seem to matter whether or not the post is tagged…

    What is going on?? What does the post tags have to do with custom meta values?!? *scratches head, utterly confused*

    I’d surely like som input on this one, it’s making my brain itch. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • How about using:

    if (get_post_custom()&amp;&amp;$quote = get_post_meta($post->ID, 'quote', true);) {
    echo "<div class=\"quote\">$quote</div>";
     }

    Tags are stored in the database in the same kind of format as meta items.

    Thread Starter Anna Johansson

    (@vintagemaniac)

    Ah! But of course, now that you say it it…

    Your code worked perfectly except for some minor stuff.

    Here’s my new (and by you improved) code:

    if (get_post_custom()&amp;&amp;$quote = get_post_meta($post->ID, 'quote', true)) {
    echo "<div class=\"quote\">$quote</div>";
     }

    Thank you for the help! =D

    Thread Starter Anna Johansson

    (@vintagemaniac)

    (argh, amps are being made into html even in backticks. annoying.)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_post_custom interfered by post tags (This is an odd one!)’ is closed to new replies.