I am attempting to create a front-end form for a template page and am using the following code. The code works allows the post to be submitted to the custom post type however, it allows the form to be submitted with no data in the fields. Also, I can't figure out how to get the redirect to work correctly.
http://pastebin.com/ts4dmW6A
I recommend to have the form handler inside functions.php or in a plugin rather than the template. If you use a hook you can then handle any form submissions there. Action field would determine which hook should be called.
More details can be found here:
https://codex.wordpress.org/Plugin_API/Action_Reference/admin_post_(action)
Related
I am familiar with elementor forms new_record hook that I can work with and add some custom actions.
I am looking for a way to add some custom metadata to the save_to_database action elementor has, which saves the form submission in the DB. I have searched and have not found any specific hook that allows me to add custom metadata.
I would like to have on the new_record hook the submission id that was stored and then I can write my own query as needed.
Does anyone know of a way to get the submission id on this hook?
Thanks
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.
I have a Wordpress website and want to add custom flow of registration.
The current website has these pages but I am not sure if there is any plugin that has inbuilt such flow feature or how to add this feature.
Any help appreciated.
I had to do a similar modification.
Your case seems the same as mine, its a single form, split onto steps for helping users/validations.
I didn't found any plugin ready for all i needed (the steps thing), and mainly ... hooks to change registration form in wordpress just add extra fields to standard fields, i needed to completly remix the order, so I went the javascript way:
Added my custom css and JS to login/register pages with the action 'login_enqueue_scripts'
Added my custom fields to form using 'register_form' action
Added a class to login body with 'login_body_class' filter, to keep things hidden while JS magic happened;
I'm not sure what's your skill level in JS, but once you got those hooks ready you can make pretty much whatever you want with the register form.
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.
How can I validate WordPress custom fields without using Javascript. I want to validate them using PHP and stop post creation on error.
You can do that using the hook save_post. There are lots of examples in WordPress Answers, check the results for +save_post +update_post_meta is:answer.
If it doesn't validate, use wp_die() and the post won't be saved.