I have created a form on my wordpress site, a function to process the data located in functions.php, and an action php file. I have tested the processing function and know it works, but I'm having trouble getting everything to communicate with wordpress.
update_item_meta.php is located in my theme directory.
Form Opening Tag
<form method="post" id="project-info" action="/wp-content/themes/Avada/update_item_meta.php">
update_item_meta.php
<?php
//connect to WP
define('WP_USE_THEMES', false);
require('../../../wp-load.php');
//call function from functions.php to process form data
update_item_meta_data();
?>
Note: wp-load.php is located in the main site root
If someone could help me out I would really appreciate it. If i had to guess it's a problem with either the path to update_item_meta.php in the form action or update_item_meta.php, but I haven't been able to figure it out.
action="/wp-content/themes/Avada/update_item_meta.php"
You will obviously not load wp calling a php file directly and using relative paths to load wp is problematic.
The best way to deal with forms in wp are to post to the same url:
action="#"
with a hidden input for a unique field to identify your form and in your functions file a function to pick up the post action....
if($_POST['unique']){
require_once 'yourfile.php';
//or your form process code here
}
action="#"
and place code to handle the post in your template file (not the wp way but helps prevent a load of code from being loaded that is not relevant to the page.
Both ways will have wp loaded for you without having to manually load.