Validating Custom Field - wordpress

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.

Related

Elementor Pro Forms - Save Submission Hook

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

Advanced custom field with short codes

Can i display the data which are in the advanced custom fields using shortcodes without editing theme codes, in my web page front end. If the answer is yes, how can i do this? If not are there any methods to do that easily without deep coding knowledge.
chatGPT says yes but I couldn’t.
Yes, you can. There is an ACF shortcode. See here: https://www.advancedcustomfields.com/resources/shortcode/
[acf field="field_name"]
You can also pass a post id to get the field of another post:
[acf field="field_name" post_id="123"]
However, this does not work for all field types. But there is a Wordpress plugin with which you can display the custom fields called ACF Views: https://wordpress.org/plugins/acf-views/

Provide Support for WP Hooks in Custom Plugin

Some wordpress captcha plugin use login_form hook to add their fields. Is it possible to provide support for login_form hook in my plugin's custom form? It means if someone use this hook to add their work it will reflect on my custom plugin's form so that i can get befefit from this.
Please help me :(
Yes, it's possible. For example, through ACF form fields that are saved in the database and can used to fetched for another query through get_post_meta. Check this out: https://www.advancedcustomfields.com/resources/acf_form/.

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.

WordPress Front End Posting

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)

Resources