开发者

Why don't these two wordpress php blocks work out the same?

开发者 https://www.devze.com 2022-12-28 05:29 出处:网络
This first bit works: $my_id = 617; $post_id_7 = get_post($my_id); 开发者_如何学JAVA$title = $post_id_7->post_excerpt;

This first bit works:

                $my_id = 617;
                $post_id_7 = get_post($my_id); 
   开发者_如何学JAVA             $title = $post_id_7->post_excerpt;
                echo $title;

While this second bit doesn't:

                $post_id_7 = get_post(617); 
                $title = $post_id_7->post_excerpt;
                echo $title;

What gives?


http://codex.wordpress.org/Function_Reference/get_post

You must pass a variable containing an integer (e.g. $id). A literal integer (e.g. 7) will cause a fatal error


yeah what Samuel said.

So if you wrote it:

$post_id_7 = get_post('617');  
$title = $post_id_7->post_excerpt; 
echo $title; 

it should work.

0

精彩评论

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

关注公众号