set post author depending on condition via frontend post submit

The wp_insert_post_data filter is the right approach. I would do something like this: add_filter( ‘wp_insert_post_data’, ‘some_handler’ ); function some_handler( $data )//$data is an array of sanitized post data { //do some conditional checking… if ( ! isset( $_POST ) ) {//the request to insert post data wasn’t done by a user return $data; } //don’t … Read more

Can i have more than one form for front end posting in one template [closed]

Yes. You can check which form is being submitted by adding a “name” attribute to the submit button. <input type=”submit” name=”form1″ value=”Submit”> Then in you validation, just check if that exists: if(isset($_REQUEST[‘form1’])){ // Form 1 } elseif(isset($_REQUEST[‘form2’])) { // Form 2 } This is one method at least, there are plenty of ways to deal … Read more

Custom Taxonomy Not Saving in Front End Post

I figured this out after much trial and error. Made some slight changes to the $new_post array. else if( !$error_msg && ‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty( $_POST[‘action’] ) && $_POST[‘action’] == “new_post”){ $new_post = array( ‘post_title’ => $title, ‘post_content’ => $description, ‘post_category’ => array($_POST[‘cat’]), // Usable for custom taxonomies too ‘tags_input’ => array($tags), ‘tax_input’ => … Read more

Check for uploaded file type wordpress way for multiple uploads

Finally figured it out. This code throws an error if the filetype is not allowed. Hope this helps some newbie save a little time. global $post;//http://wordpress.stackexchange.com/questions/39753/ if ($_FILES) { $files = $_FILES[‘upload’]; foreach ($files[‘name’] as $key => $value) { if ($files[‘name’][$key]) { $file = array( ‘name’ => $files[‘name’][$key], ‘type’ => $files[‘type’][$key], ‘tmp_name’ => $files[‘tmp_name’][$key], ‘error’ … Read more

Add/remove tags on frontend programmatically

Found the solution in https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/taxonomy.php#L0 wp_add_object_terms() uses wp_cache_delete(), but wp_remove_object_terms() don’t. Just added this: wp_remove_object_terms( $post->ID, $tag_id, ‘post_tag’ ); wp_cache_delete( $object_id, ‘post_tag_relationships’ );

How to request admin-ajax.php correctly when wordpress URL and site URL are different?

admin_url() should be used. However for some websites this request gives error 404 in front-end admin_url(‘admin-ajax.php’) should point to an actual file (admin-ajax.php), as such WordPress won’t pass it through index.php, and so it shouldn’t lead to the theme’s 404 page. (Unless the file has been deleted). … unless you have a .htaccess file which … Read more

Showing user profile data on front-end

You are trying to access the meta data of the user with ID stored in $user->ID but the object $user is not defined in your code. You are also using an undefined variable $user_ID. The quickest fix in your code would be to change this: get_the_author_meta( ‘province’, $user->ID ) ) With: get_the_author_meta( ‘province’, $userdata->ID ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)