1

我一直在尝试遍历这个数组,但我根本无法检索帖子标题。它可能是我缺少的一些东西,但我无法正确处理。

Array
(
[0] => WP_Post Object
    (
        [ID] => 5366
        [post_author] => 1
        [post_date] => 2013-07-09 12:06:00
        [post_date_gmt] => 2013-07-09 12:06:00
        [post_content] => 
        [post_title] => Mini Face Lift
        [post_excerpt] => 
        [post_status] => publish
        [comment_status] => open
        [ping_status] => open
        [post_password] => 
        [post_name] => mini-face-lift
        [to_ping] => 
        [pinged] => 
        [post_modified] => 2013-07-09 12:06:00
        [post_modified_gmt] => 2013-07-09 12:06:00
        [post_content_filtered] => 
        [post_parent] => 17
    )
    )

如果我想获得帖子标题 - 我该怎么做?我非常感谢您的帮助,因为我被困住了。

非常感谢提前!

4

2 回答 2

13

It's not a multi-dimensional array, but an array of objects . . . try something like:

$varName[0]->post_title

Alternatively:

$varName[0]['post_title']

If you're trying to iterate and get each title, you probably want something like:

foreach ($varName as $key=>$wpPostObject) {
    echo $wpPostObject->post_title;
}
于 2013-07-10T21:25:22.160 回答
0

尝试:

$examplePost = get_post(); //Post object you are retrieving

echo apply_filters( 'single_post_title', $examplePost->post_title ); //echos the post name, use the_content instead, if you are doing this in the loop
于 2013-07-10T21:46:27.147 回答