Reputation: 861
I trying to get deep into WordPress development, I was wondering when we do var_dump($post->post_id)
, it gives a list of objects that, that function has. The reason I said objects, is I don't know what they are. While it gives you a comprehensive list of properties that you can access as the WordPress codex page state. My question is how can I access other function and its properties like:
`get_the_category();`, I might be naive to get a list of properties like
$category = get_the_category();
foreach ($category as $cat) {
echo $cat;
}
How can I access properties of a WordPress function, a example would be something like $category->ID()
or other properties, other example might include
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
?>
<?php
$test = get_cat_ID($post->ID);
var_dump($test)
?>
<?php }
}
?>
But in that example, I get a int(0)
, so how can I get different properties on a post, like its category, slug, taxonomies etc.
Upvotes: 0
Views: 1853
Reputation: 9311
I think what you're trying to do is to get information about the API programmatically. The problem is that PHP is not well suited to do something like that, because there are not static types. In any case, Wordpress makes use of on-the-fly generated objects and associative arrays. If the template function would actually return objects of a certain type, you could definitely look up the properties of this type and have your answer.
However, as this is not the case, all you really can do is to call the function in question once and then take a look at the result. In your case for example:
$category = get_the_category();
var_dump($category);
Of course, you could also take a look at the code to figure out how the result value will look like. This is quite cumbersome though, because there are usually a myriad of other functions being called to assemble the result.
Note: This will not work with all functions. There are some that actually output the result rather than returning it. You don't really need to investigate these, however, because their result is only a single string. (You can recognize these functions usually by their prefix the_
, but not get_the_
as in your example.)
If I totally missed your point, let me know and I'll try again. ;-)
Upvotes: 1