Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related Posts: add list of post IDs to WP REST API Post responses #3424

Closed
jeherve opened this issue Feb 18, 2016 · 2 comments
Closed

Related Posts: add list of post IDs to WP REST API Post responses #3424

jeherve opened this issue Feb 18, 2016 · 2 comments
Assignees
Labels
[Feature] Related Posts [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Milestone

Comments

@jeherve
Copy link
Member

jeherve commented Feb 18, 2016

The WordPress.com REST API includes the /sites/$site/posts/$post/related endpoint, that we use to get related post IDs for a specific post. We then use the _jetpack_related_posts_cache post meta to store the IDs of each Related Post locally.

It's useful, but that data can't be accessed by the core WP REST API.

It would be nice if we could register a new field in the API to expose these post IDs, maybe in a jetpack-related-posts array under wp-json/wp/v2/posts/$post.

This would make it easier for folks developing themes using the WP REST API, and wanting to use Jetpack Related Posts without having to do remote queries to the WordPress.com REST API and handling caching themselves.

@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Related Posts labels Feb 18, 2016
@jeherve jeherve added this to the 4.0 milestone Feb 18, 2016
jeherve added a commit that referenced this issue Feb 18, 2016
Fixes #3424

To test:
1. Install and activate the WP REST API plugin (v2)
2. Make sure Related Posts are enabled in Jetpack.
3. Visit `http://yoursite.com/wp-json/wp/v2/posts`
4. Look for the new `jetpack-related-posts` field
@jeherve jeherve changed the title Related Posts: add list of post IDs to WP REST API Post responses Related Posts: add list of post IDs to WP REST API Post responses Feb 18, 2016
@jeherve jeherve self-assigned this Feb 18, 2016
@jeherve jeherve modified the milestones: 4.3, 4.1 Jun 17, 2016
@richardmuscat richardmuscat modified the milestones: 4.3, 4.4 Jul 7, 2016
@jeherve jeherve modified the milestone: 4.4 Jul 8, 2016
rcoll pushed a commit that referenced this issue Aug 29, 2016
Fixes #3424

To test:
1. Install and activate the WP REST API plugin (v2)
2. Make sure Related Posts are enabled in Jetpack.
3. Visit `http://yoursite.com/wp-json/wp/v2/posts`
4. Look for the new `jetpack-related-posts` field
zinigor pushed a commit that referenced this issue Oct 21, 2016
* Related Posts: add posts to the WP REST API Post Response.

Fixes #3424

To test:
1. Install and activate the WP REST API plugin (v2)
2. Make sure Related Posts are enabled in Jetpack.
3. Visit `http://yoursite.com/wp-json/wp/v2/posts`
4. Look for the new `jetpack-related-posts` field

* Related Posts: updated version numbers in docblocks.

* Related Posts: only register the field when the function exists.

@see #3425 (comment)
@ziyafenn
Copy link

ziyafenn commented Sep 21, 2018

Hey guys, don't know if this is related, but seems to be related custom post types are not added to the REST API when related default post types are.
I added the function in my functions.php

function allow_my_post_types($allowed_post_types) {
    $allowed_post_types[] = 'article';
    return $allowed_post_types;
}
add_filter( 'rest_api_allowed_post_types', 'allow_my_post_types' );

@zinigor

@jeherve
Copy link
Member Author

jeherve commented Sep 21, 2018

@ziyafenn Sorry that you are running into issues. Could you contact us via this contact form and give us more details and examples there, so we can help you get this fixed?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Related Posts [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

No branches or pull requests

4 participants