开发者

How to get post_id from post_meta

How can we get post_id from post_meta by given meta_key,

I want to get post_id from post_meta where meta_ke开发者_开发知识库y is :

_wp_page_template

and meta_value is

my_page_template.php

Would like some help please.

Thanks


Put this in your functions.php an then call it when you want

 function getIdFromMeta( $meta_key, $meta_value ) {
    global $wpdb;
    $pid = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = '$meta_value' AND meta_key = '$meta_key' ORDER BY post_id DESC") );
    if( $pid != '' )
        return $pid;
    else 
        return false;
}

Hope it helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜