I installed the JSON API Plug-In for my wordpress site. I want to display on an external site how many posts I have in a certain category.
For example, I have a URL like this: http://mywordpress.com/?json=get_category_posts&slug=press%20releases
Along the output, I almost immediately see a field “post_count” and a number right after it. I want to encapsulate this number into a string so I can output that number onto a table. But in order for me to be able to do that I need to have the entire output in a variable.
But I can’t have something like
$json-output = http://mywordpress.com/?json=get_category_posts&slug=press%20releases;
echo $json-output;
That’s just gonna output the URL, not the result of the JSON query.
I hope the question is making sense. Any guidance would be appreciated.
You will need to use CURL to get the json result from the URL, then parse the json with PHP, then echo the item you would like displayed.
The parts you seem to be missing are the CURL and JSON parsing, but you are on the right track.
This might help, a pretty simple example:
http://www.katcode.com/http-requests-using-curl-and-decoding-json-responses/