How to write a select statement in WordPress file like “function.php”

I tried this code in phpmyadmin before and it works fine

SELECT meta_value
FROM wp_postmeta
INNER JOIN wp_posts ON post_id =564
WHERE meta_key =  'max_person';

But I don’t know how to insert it in function.php

Read More

I insert this code and it works

<? PHP 
    $postid = get_the_ID();
    $maxperson = $wpdb->get_row( $wpdb->prepare(
    "SELECT meta_value FROM wp_postmeta inner join wp_posts ON post_id= %d WHERE meta_key = 'max_person'", $postid
        ) );
?> 

But when I var_dumped $maxperson var_dump ($maxperson); it returns

object(stdClass)#634 (1) { ["meta_value"]=> string(1) "5" }
the result should be “5” i dont understand what that means

Related posts

Leave a Reply

2 comments