How to add post ID to JSON URL?

2019-08-17 13:00发布

问题:

I am not familiar with PHP Syntax. Now i added JSON Plugin to my wordpress website and activate it.

When i open url to get_recent_post , it's fine. JSON data are showing.

But when i open get_post , it's only showing

{"status":"error","error":"Include 'id' or 'slug' var in your request."}

So i don't know how to add post id to that URL.

here is the pic. Another get_page , gate_date_posts, etc... links are same showing error.

How can i do it?

回答1:

To display a post's ID, simply use the following PHP code within the WordPress loop:

<?php the_ID(); ?>

To return the ID, use the following PHP code within the WordPress loop:

<?php get_the_ID; ?>

To get a post's id outside of the WordPress loop use the following PHP code:

<?php global $post; $post->ID ?>

Hope that helps you.



回答2:

http://yoursite.com/api/get_posts/

with the s

If you use the WordPress link and click on it, you will be fine.