The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] How to get "key" from "value" in custom meta (4 posts)

  1. mubojason
    Posted 5 years ago #

    i have a single post's custom meta, ex:
    custom meta key = moviename
    custom meta value = HarryPotter

    i can use code:
    <?php echo get_post_meta($post->ID, 'moviename', true); ?>
    to get the post's custom meta value "HarryPotter"

    but, how can i get the custom meta key "moviename",
    with the value "HarryPotter" that i know?

    please help me!

  2. Michael
    Forum Moderator
    Posted 5 years ago #

    $customkeys = $wpdb->get_results("SELECT meta_key FROM $wpdb->postmeta WHERE meta_value = 'HarryPotter'");
    $meta_key = $customkeys[0]->meta_key;

    based on:

  3. mubojason
    Posted 5 years ago #

    and more,
    if HarryPotter from a Variable like $name2,
    how to get it?

  4. mubojason
    Posted 5 years ago #

    ok, i get it!
    thanks for answer my first question~

Topic Closed

This topic has been closed to new replies.

About this Topic