0

I am someone who has been trying out webdesign for around 2 months now and I have a question. So I have the following array with object:

array(1) {
  [0]=>
  object(WP_Post)#416 (24) {
  ["ID"]=>
  int(36)
  ["post_title"]=>
  string(7) "Bakuman"
}

I am trying to get the value of "ID", but am not sure how to go about referencing it.
I have tried [0]["ID"], but doesn't work.

Also: Is it possible to get the ID without mentioning the #416 number?

Tried searching for answer, but keep coming up with results that have large amounts of OOP with so much info I can't filter through to what I need. Can anyone hlpe me out?

0

2 Answers 2

1

PHP uses -> for object properties.

So in your case

echo $array[0]->ID;

should output 36

where [0] is the first element of $array which contains the WP_Post object and ID is the property containing the value you're looking for

Sign up to request clarification or add additional context in comments.

1 Comment

@downvoter care to provide some constructive feedback by leaving a comment? or are you just going with hitting the -1 button?
1

The 0th element of your array is in fact an object, so to access its properties, you need to use the object referencing operator ->.

Try this: $array[0]->ID

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.