Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. function my_pre_save_post( $post_id )
  2. {
  3. // check if this is to be a new post
  4. if( $post_id != 'new' )
  5. {
  6. return $post_id;
  7. }
  8.  
  9. // Create a new post
  10. $post = array(
  11. 'post_status' => 'draft' ,
  12. 'post_title' => 'A title, maybe a $_POST variable' ,
  13. 'post_type' => 'post' ,
  14. );
  15.  
  16. // insert the post
  17. $post_id = wp_insert_post( $post );
  18.  
  19. // update $_POST['return']
  20. $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
  21.  
  22. // return the new ID
  23. return $post_id;
  24. }
  25.  
  26. add_filter('acf/pre_save_post' , 'my_pre_save_post' );
  27.  
  28. $postid = get_the_ID();
  29. if($postid ==50){ //50 is a Page I created for the Form
  30.  
  31. $options = array(
  32. 'post_id' => 'new',//$post->ID, // post id to get field groups from and save data to
  33. 'field_groups' => array(46), // this will find the field groups for this post (post ID's of the acf post objects)
  34. 'form' => true, // set this to false to prevent the <form> tag from being created
  35. 'form_attributes' => array( // attributes will be added to the form element
  36. 'id' => 'post',
  37. 'class' => '',
  38. 'action' => '',
  39. 'method' => 'post',
  40. ),
  41. 'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
  42. 'html_before_fields' => '', // html inside form before fields
  43. 'html_after_fields' => '', // html inside form after fields
  44. 'submit_value' => 'Update', // value for submit field
  45. 'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
  46. );
  47. acf_form( $options );
  48. }
  49.  
  50. $posts = get_posts(array(
  51. 'post_type' => 'event',
  52. 'posts_per_page' => -1,
  53. 'meta_key' => 'location',
  54. 'meta_value' => 'melbourne'
  55. ));
  56.  
  57. if($posts)
  58. {
  59. foreach($posts as $post)
  60. {
  61. the_field('titel');
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement