WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get_post_custom interfered by post tags (This is an odd one!) (4 posts)

  1. Anna Johansson
    Member
    Posted 5 years ago #

    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. ;)

  2. tomontoast
    Member
    Posted 5 years ago #

    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.

  3. Anna Johansson
    Member
    Posted 5 years ago #

    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

  4. Anna Johansson
    Member
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic