Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1054 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'Cannot use object of type stdClass as array' using Wordpress

#1
I am trying to retrieve the slug for a tag inside a wordpress post, now its possible to get all tag info using

$tag = wp_get_post_tags($post->ID);

More info on this on the [Wordpress Docs][1]


[1]:

[To see links please register here]


By using this you should get data returned like this...

Array
(
[0] => stdClass Object
(
[term_id] => 4
[name] => tag2
[slug] => tag2
[term_group] => 0
[term_taxonomy_id] => 4
[taxonomy] => post_tag
[description] =>
[parent] => 0
[count] => 7
)

[1] => stdClass Object
(
[term_id] => 7
[name] => tag5
[slug] => tag5
[term_group] => 0
[term_taxonomy_id] => 7
[taxonomy] => post_tag
[description] =>
[parent] => 0
[count] => 6
)

)

Now what I want is the slug for the first item which should be as follows

$tag[0]['slug']

However by doing so I recieve this php error:

> Cannot use object of type stdClass as
> array

Can someone tell me what I'm doing wrong here? and whats the best way to get the slug data
Reply

#2
Note that the array contains *objects* (instances of `stdClass`), not other arrays. So the syntax is:

$tag[0]->slug
Reply

#3
Another option should be to explicitly cast $tag[0] into an array:

$t = (array)$tag[0];
$t["slug"] = ...

Can't get it to work though
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through