Wordpress hyperlink using REST API
Does anyone know how to add hyperlinks in Wordpress articles using the WP REST API ?
I can't find any tutorial/documentation about this, thank you !
1 answer
-
answered 2022-05-05 09:49
Richard BEN
I found an alternative way to do it easily:
simply add hyperlinks through the WP article writer interface then click on "Edit in HTML" then you can copy paste the html code of any given paragraph into your WP Rest API content.
do you know?
how many words do you know
See also questions close to this topic
-
How to upload a video using ACF in WordPress?
I am still at learning phase in WordPress. I cannot figure out in ACF which field type should I choose to upload a video file and which code should I write to show it at the front-end. Please look into the below code. I am using the_field('') but it isn't working. Can anyone help
<video width="954" height="535" controls class="tm-mb-40"> <source src="video/wheat-field.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
-
Can you add apps made from (js, nodejs, express and mongodb) in a wordpress website?
I already have a wordpress website. I studied web development using js, node.js, express and mongodb and build some projects. I would like to add it to my website. Is this possible or I just need to create a website without wordpress and add my projects?
-
Query to get Woo products in a parent-children order
I want to build a MySQL query for a Woo database schema to get simple/variable products, but in a specific order: I want to get them in an
ID
ASC
ending order, but when a variable product is met, I want to get the variations exactly below their parent.So for a simple product, or the parent of a variable product, the
post_type
field is set to 'product' and thepost_parent
field is set to 0. For the children of a variable product (a.k.a variations) thepost_type
field is set to 'variable_product' and thepost_parent
field is set to theID
of the parent product.So, imagine this desired order:
ID post_title post_type post_parent 1100 title1 product 0 1104 title2 product 0 1130 title2 - variation1 variable_product 1104 1200 title2 - variation2 variable_product 1104 1208 title2 - variation3 variable_product 1104 1107 title3 product 0 1111 title4 product 0 1205 title4 - variation1 variable_product 1111 1210 title4 - variation4 variable_product 1111 1430 title4 - variation3 variable_product 1111 1432 title4 - variation2 variable_product 1111 So by the above table you see that I want products to be sorted by their ID, until the variation(s) of a product are met, which I want to be placed under their parent, and get sorted themselves by their ID also. So I don't care about titles not being sorted alphabetically (title4-variation4 is sorted above title4 - variation3 because the variations' IDs are sorted in an ascending order).
So I tried to play a little with
ORDER BY ID ASC, post_parent ASC
and alsoORDER BY ID ASC, post_type ASC
because product is sorted alphabetically above variation_product, but I couldn't get them sorted correctly. I always end up with parent products being sorted higher than variations, just because their IDs are smaller.SELECT * FROM wp6c_posts WHERE post_type IN ('product', 'product_variation') ORDER BY ID ASC, post_parent ASC;
Obviously I have to query table wp6c_posts twice, once for the simple/parent products, and then for the variations of the variable products, but I can't think of the correct query.
Can someone help me with this?
-
Display post title from WordPress excluding a string via API
Imagine you have custom post types - Users. There are fields for each user as the post title, description, image, and rules. All titles are names of the Users and all they have Mr. before the names. What is the correct way and how to display all these fields via API in another site(not WordPress) but for the titles to exclude/strip the string Mr.?
-
Wordpress REST API in reactJS
I want to make a ReactJS blog with wordpress CMS as backend. I am using wordpress rest api but I can't get featured image of posts. so I installed a plugin that it give me the url of images but I don't know how can I use it as a "src" for image? please tell me how can I make this:
{{__html: post.featured_media_src_url}}
to a string?
I tried:
<img src={String({__html: post.featured_media_src_url})}/>
it doesn't work
-
How to get a certain post, its tags and comments from Wordpress REST API using switchMap and then combine the resulting values using JS?
I am working on an Angular app that needs to fetch a certain post with a given ID, its respective tag names and comments from Wordpress REST API. This application works much like StackOverflow's question-answer-logic, so I will be referring to the Wordpress post as a
question
and the Wordpress comments asanswers
. With the API threeGET
requests need to be sent to the server. The first request is being sent to/wp/v2/posts/<id>
. The response from the server looks like this:Excerpt of post request:
{ "id": 9, "title": { "rendered": "Hello World! 3" }, "tags": [ 2, 3, 4 ] }
The numbers in the
tags
arrays aren't the actual human-readable tag names, they're just the identifiers for the tags. After we have received the first response from the server, we need to send anotherGET
request to the server to/wp/v2/tags?include=2,3,4
while supplying the tag identifiers with it. We don't need every single tag available in the database, just the ones that were referenced to in the response to the first request. In other words, the second request depends upon the results of the first request. The second request's response from the server looks like this:Excerpt of tags request:
[ { "id": 8, "name": "test" }, { "id": 9, "name": "test2" }, { "id": 30087, "name": "test3" } ]
The third and final request needs to be sent to
/wp/v2/comments?post=9
. This will limit result set to comments assigned to the specific post ID. The response from the server looks like this:Excerpt of comments request:
[ { "id":3, "post":4, "content":{ "rendered":"<p>This is an example comment number 3.<\/p>\n" } }, { "id":2, "post":9, "content":{ "rendered":"<p>This is an example comment number 2.<\/p>\n" } } ]
Angular RxJS'
switchMap
operator seems to be the way to go. My requirements are as follows:- call posts/3 (post id number is gathered from URL parameter
https://angular-ivy-jhuhth.stackblitz.io/detail/3
) - take ID from post
- call tags with ID
- call comments with ID
- using vanilla JavaScript merge tags and comments with posts and return (so that the combined object has a key called
tag_names
and comments' content and date)
then
.subscribe()
to the overall flow and get a combined object of the post, its tags and comments which can then be iterated over in the Angular template.EDIT: In the template I need to display title, date, content and human-readable tag names for the question/post and also content and date for the answer/comment.
My code in Stackblitz so far looks like this. Forks to my code would be greatly appreciated. At the tome of coding the solution, I experienced a console error:
questions.map is not a function
on line 44 indetail.component.ts
. I need to fix this in order to continue the work.Two concepts used in the code:
- forkJoin RxJS operator, which basically waits for all the Observables to complete and then combines the result.
- async pipe, which subscribes to an Observable or Promise and returns the latest value it has emitted
- call posts/3 (post id number is gathered from URL parameter