1

I have been trying to loop through this array but I simply cannot retrieve the post title. Its probably a little something I am missing but I can't get it right.

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
    )
    )

If I want to get the post title -- how do I do it? I'd really appreciate your help as I am stuck.

Huge thanks in advance!

2 Answers 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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

You're an absolute star! Thank you so much!!
0

Try:

$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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.