how can we create posts and pages using wordpress REST APIs? - wordpress

I have a preformatted HTML string that I want to use to create a POST or PAGE through wordpress REST APIs. The purpose is to avoid formatting after the POST or PAGE is created.
The problem is wordpress apis to create post/page do not take HTML as a parameter.

I think you can pass your content as a json format. Please check the screenshot

Related

Is it possible to create custom entities (entries if you take up the strapi vocabulary) in wordpress?

Edit : the thing I was looking for is called Custom Post Type in the WordPress World
Disclaimer: it is my first steps with WordPress and I realize I do not have the right vocabulary to make a proper google search, so please excuse me if this answer has been already asked many times ...
I'm working on a website that use an old preexisting WordPress as headless CMS.
On this new website, I need to display some "job offers"
On the preexisting WordPress, those job offers are just HTML blocks embedded in a page. So I can't get only those without having the embedded page HTML and CSS
If I could have created a custom REST API to get those "job offers", I would have said that those resources would look like this :
{
title : string,
description: string
}
My first idea would be to create a WordPress custom end point, but I do not know if it is possible to create custom entities (entries (?) If I take up the vocabulary of strapi)
Is this something that can be done?
I've tried :
basic google search
reading the strapi and wordpress documentation
I expect to be referred to a solution or to know what to search
The thing you're looking for are Custom post types if that can help a plugin called ACF can help with the custom fields.

How can I fetch the post slugs of all languages?

I have a react project which fetches data on wordpress via api calls (plugins installed: ACF and WPML).
I have the Event CPT and viewing the page localhost: 3000 / events / first-event, I retrieve the information via the slug.
If on this page I wanted to retrieve the same event in another language, I could add the country code in the url and make a redirect.
It is possible that the same event has different slugs based on the language and the feature does not work.
Do you have any ideas on how to make this feature?
Thank you guys!
I have temporarily modified the pathname.
<a href={window.location.pathname.replace('/','/en/')}>EN</a>
I have found the solution.
I used the icl_get_languages() function to fetch the languages, icl_object_id() to retrieve the post id of a language, get_post to retrieve all fields and update_post_meta to add a custom field to the post.
Hey I have the same setting but not with React.
If you are using the API without any modifications in the class and given that the title between language is the same try the following:
/wp-json/wp/v2/posts/?post-slug=second+post&lang=fr
and page slug
/wp-json/wp/v2/pages/?page-slug=second+post&lang=fr
However, you need to modify the API response if you want your ACF fields to be there (or use a plugin).
Also mind that post ID between translations is different. Ensure to include the lang as argument in the modification of the WP_REST_Controller. https://developer.wordpress.org/reference/classes/wp_rest_controller/get_collection_params/
Let me know if that helps.

How do I use gravity form fields on a thank you page in Wordpress?

I’m using gravity forms in WordPress and have set it up to redirect to a thank you page.
I want to pull the persons name from the query string that gf produces but I have no idea how to get this on the the page in WordPress.
All I need is:
“Thank you NAME for contacting us. We’ll be in touch within 24 hours.”
Can anyone tell me how to pull the name from the url and print it on the page as in the above example?
Thanks.
GF Post Content Merge Tags provides the ability to include submitted data in page content via Gravity Forms' merge tags.

Create custom wordpress url to query data from external database

so, I have a Wordpress Setup with a custom homepage template. In the template I query some products from an external database. Now I want to create a detail of a product, and this is where im stuck..
I don't know how to implement this since there is no data in the WP db thus no actual url (I guess?).. I thought about making 1 page in WP called 'Detail' and make the href attribute on the homepage products like this 'www.example.com/detail/123', get the id from the url en with that id query to the database..
Is this the right approach? Hope someone can help..
thanks!
If i understand you right, you want to query content from one wordpress website to another right ?
The right way to do it is to use JSON APIs which will let u retrieve the content you need using HTTP requests.
You can set these APIs yourself, refer to the following tutorial.
Thus, you can also use this wonderful wordpress plugin :
JSON API
After installing and enabling the plugin you'll have to set your API links according to the content you need to get, for example the following api:
http://example.com/api/get_posts/?post_type=custom_post_type&count=3
queries the latest 3 custom posts along with their fields and custom fields (if present).
Find more examples here.
Now on your other website where you want to display the content you 'll need to use JSON decode to convert the JSON string into a PHP obect or array.
For example:
$json = '{"a":hello,"b":hi,"c":hey,"d":yo,"e":ola}';
$data = json_decode($json);
echo $data->{'a'}
// this should echo the value "hello"
As stated here.
I hope that helps !
I don't think he wants to query another WordPress. He only says that he fetches data from another database that contains products.
Your idea is pretty close to what you have to do. Take a look at add_rewrite_rule, add_rewrite_tag and get_query_var.
This tuts is a good example for you: http://code.tutsplus.com/articles/custom-page-template-page-based-on-url-rewrite--wp-30564

Need to clone a existing wordpress admin page

I need to create a new page which will have same functionality of one the page of admin.
I have a page which is accessed by /wp-admin/post-new.php?post_type=shop_order.
I have made a copy of this page by the name "new-post0.php" but when I access new cloned page , its content is different!
I m missing something at registering this new page?
You shouldn't copy and paste Wordpress core files. That's called "hacking the core" which is very very bad.
http://websynthesis.com/dont-hack-wordpress-core/
You should instead develop your "new-post" page as a new custom post type.
You can learn about them here:
http://codex.wordpress.org/Post_Types
The link /wp-admin/post-new.php?post_type=shop_order you posted refers to a new post page for a custom post type.
To get another page like that, you'll need to create another custom post type and add the custom meta fields.
If you can't code it, there are plugins that you can use to achieve the same results.
Custom Post Type UI to create custom post types and ACF for custom fields. Right now, you should download ACF from Github.

Resources