I have created a blog on Wordpress.com, I can access the api and returned posts from the homepage with this:
https://public-api.wordpress.com/rest/v1/sites/{siteID}/
So my blog is access via URL at something like www.blog.home.blog
However I have a second page that is at www.blog.home.blog/secondPage
The API doesn't return Posts from this URL. Trying to understand what I need to change to the API URL to return posts from this second page?
You need to provide the ID of this page/post you are trying to access. It will be something like https://public-api.wordpress.com/rest/v1.1/sites/$site/posts/$post_ID And to get all the posts you can use https://public-api.wordpress.com/rest/v1.1/sites/$site/posts/
More info is available here at the official wordpress.com documentation for developers.
Related
I have a fresh install of the latest version of wordpress. I need to pick up a certain post by slug from the REST API, but the response is always all posts instead of the one.
My route
I cannot find the reson I'm getting all posts as the response anywhere on the internet. What am I missing??
By default, WordPress will work with slug filtering but in your scenario, it shows all posts created. I found an alternative way & try below link which shows only mentioned slug data.
REST API
I have a Wordpress site and a Laravel site and I want to display recent wordpress posts in the footer of Laravel site. How can I do this without having my wordpress database information in my config/database.php file and using it in the models? Can I get them using RSS?
Recent WordPress was released with a huge thing called REST API – earlier it was possible only with external plugins. So now we can query WordPress database from external projects. Including Laravel.
set up a local WordPress website, and after installation you got that usual dashboard.
we can already make API calls after installation. No need to configure anything, we just launch the URL in the browser:
we’ve received a JSON with a list of posts – by default, WordPress creates one dummy post.
Basically, URL structure for the API calls is simple:
/wp-json/wp/v2/[endpoint]?[parameters]
Yes, you’ve read it right, we can get posts, categories, tags and other things that are publicly available, so we don’t need any authentication here.
And we also can filter the data with GET parameters, like this:
/wp-json/wp/v2/posts?per_page=2&orderby=title
For more details open link:- Using WordPress REST API in Laravel
You can get the posts by calling an API endpoint:
yoursiteurl/wp-json/wp/v2/posts
It will return all the posts in a json format. You can also see the reference from here.
We want to use the Wordpress Rest-API to build a page decoupled from the backend. A few things still bother us though:
Within the wordpress backend one can add links in the content editor of a page or a post and one gets normally a list of all existing pages and posts of the same page to link to them. By decoupling the backend it does not know the exact urls to other pages and we need to provide this. Is there a possibility to tell wordpress what links are available?
Thanks in advance.
Cheers
For those looking for the answer:
There are two URL settings under Settings > General.
WordPress Address (URL) should be the URL for your api site. Like api.whatever.com.
Site Address (URL) should be the URL for the frontend. Like www.whatever.com.
This allows the internal linking to work properly in the Editor while keeping the backend site on a separate URL from a headless frontend.
I'm not sure what you're trying to ask. The WordPress REST API just provides a way to access posts, etc. from somewhere else part from the web site side (e.g. themes, etc). Pages would still be accessible from the admin backend and the JSON/REST API: https://developer.wordpress.org/rest-api/reference/pages/
Specifically with WordPress you could ensure that you're not rewriting the permalinks. That way they are all still site.com/?p=post-id
That way it's easy to parse fetch the new pages. Then replace the hrefs with whatever your frontend needs.
You could use the ID to fetch the slug of the new post immediately.
Or you could even keep a mapping in your presentation layer of IDs to your own slugs.
Changing the site_url doesn't work for me.
Since I also have a wordpress theme with custom rest controllers
Plus the wp-json breaks if I change the site url
My backend is hosted at digital ocean app
My frontend is hosted at vercel
I fixed it by using a wordpress plugin called make-paths-relative
But since my backend doesnt know where my frontend is I added one change within the plugin at:
frontend/class-make-paths-relative.php line 123
I added a constant FRONTEND_URL which i define in the wp-config
$relative_link = FRONTEND_URL.$link;
This changes both the permalink within my backend of a post, page or cpt
And changes internal links as wel, links within the content editor
I made a request to the plugin author as well
I have a site created with wordpress and I would like to inform all my visitors about the latest uploads and/or posts.
I tried to use WP RSS Aggregator, but I can't even get my feed using: https://dir.szkt.hu/feed/ as suggested in wp codex.
I do not get a basic feed list, just a bunch of crapy code:image
Ps help me.
Thx
The URL that you included in your question is going to a login page.
The most likely situation is that you, in your browser, logged into your site, are seeing the raw XML code of the feed. But when you put the URL into a feed reader, that software is not authenticated to the site. It sees the HTML of your login page, just like any random visitor to the site would.
Since the login page's HTML is not a valid feed, you get an error:
Invalid feed URL
The probable solution: you need to make the feed URL public, and not require a login to view it.
It is the feed. Use some feed reader to view it correctly.
I'm currently working on application where I want to use data from my blog which is hosted on digital ocean. I have installed wordpress for the blog on the server with domain name abc.com. I have to call wordpress rest api to get data without authentication if possible or using application client secret key. How we can do that?.
While calling like this "https://public-api.wordpress.com/rest/v1.1/sites/abc.com/posts/?pretty=true"
this return
{
"error": "unknown_blog",
"message": "Unknown blog"
}
do you mean
abc.com/wp-json/wp/v2/posts
url like this will get the all posts title content, and if you want to get single post, you can do
abc.com/wp-json/wp/v2/posts/1
1 is post_id , you can replace with other post id
Below function is useful for register endpoint for creating API from function.php file. Refer below link for further deployment.
register_rest_route
https://developer.wordpress.org/reference/functions/register_rest_route/
Below link is very helpful for create API in WP environment.
http://v2.wp-api.org/
You can get overview from below word press popular plugin as well, but in latest word press there is no need to use this plugin as default word press provide almost all functionalities.
WP REST API (WP API)