0

I'm working on WordPress plugin, It have a variable called $item, which holds some data of a post.

I use var_dump function to display it's data,

var_dump($item);

but i couldn't able to get a value of a single item.

I just need to get item_id and item_order

Can someone help me to get this values and assign to a another variable. Thank You

Here is the dump

object(LP_Lesson)#11313 (5) { 
    ["id"]=> int(6915) 
    ["post"]=> object(WP_Post)#11357 (29) { 
    ["ID"]=> int(6915) ["post_author"]=> string(1) "1" 
    ["post_date"]=> string(19) "2015-06-05 04:29:56" ["post_date_gmt"]=> string(19) "2015-06-05 04:29:56" ["post_content"]=> string(5971) "" ["post_title"]=> string(20) "Add and manage users" ["post_excerpt"]=> string(1) " " ["post_status"]=> string(7) "publish" 
             ["post_parent"]=> int(0) ["guid"]=> string(66) "test" ["menu_order"]=> int(0) ["post_type"]=> string(9) "lp_lesson" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" ["section_item_id"]=> string(1) "3" 
        ["section_id"]=> string(1) "1" 
        ["item_id"]=> string(4) "6915" 
        ["item_order"]=> string(1) "3" 
        ["item_type"]=> string(9) "lp_lesson" } 
        ["content"]=> string(0) "" ["lesson_type"]=> NULL ["_item":protected]=> object(WP_Post)#11357 (29) { ["ID"]=> int(6915) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2015-06-05 04:29:56" ["post_date_gmt"]=> string(19) "2015-06-05 04:29:56" ["post_content"]=> string(5971) "
7
  • 1
    have you tried anything so far, accessing the data that you need Commented Aug 16, 2017 at 11:17
  • 1
    Since its a PHP object isnt it just $item->item_id ? Commented Aug 16, 2017 at 11:17
  • 1
    did you try $item->id & $item->post->item_order ? Commented Aug 16, 2017 at 11:22
  • @Regolith I tried by echo $item->get_item_order(); echo $item-['tem_order']; but no results Commented Aug 16, 2017 at 11:23
  • 1
    @AliAwwad i appreciate if you can post this an answer, I can accept that, Thanks for the help Commented Aug 16, 2017 at 11:30

2 Answers 2

1

since it is an object, just echo

$item->id & $item->post->item_order

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

Comments

1

Did you try:

$item_id = $item->item_id

and

$item->post->item_order; //as instructed by @AliAwwad

? By the way, I see that the id, is the same with item_id, so for that for sure you can do:

$item_id = $item->id;

Is there some scope indication that I'm failing to see?

2 Comments

It's an object, so accessing it as an array is not going to work.
Thank you for pointing it out! I've been going front and back to python the last couple of weeks and my syntax gets mixed up!

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.