WordPress.org

Ready to get started?Download WordPress

Forums

How to display diffrent content based on the meta_value (4 posts)

  1. krystiank
    Member
    Posted 3 years ago #

    <?php $my_query = new WP_Query('meta_key=Product&meta_value=Shirts') ?>

    How can I use above in some kind of conditional statement.

    I need to display different content based on the meta_value that is entered into the custom field

    Thanks

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    How about:

    <?php $type = get_post_meta('Product', true);
    $my_query = new WP_Query('meta_key=Product&meta_value=' . $type);
    ?>
  3. krystiank
    Member
    Posted 3 years ago #

    Awesoe, now how can I use this for such a scenario:

    <?php $type = get_post_meta('Product', true);
    $my_query = new WP_Query('meta_key=Product&meta_value=' . $type);
    ?>

    if meta_value = white, show this content

    else if meta_value = brown, show this content

    else if meta_value = red, show this content

    etc.

    sorry, but I simply cannot write it. Can you help me writing conditional statement for meta_value

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    The code should work "as is".

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.