How to add post ID to JSON URL?

2019-08-17 12:19发布

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.

enter image description here

How can i do it?

2条回答
不美不萌又怎样
2楼-- · 2019-08-17 12:42

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

with the s

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

查看更多
干净又极端
3楼-- · 2019-08-17 12:45

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.

查看更多
登录 后发表回答