Last active
November 5, 2017 17:14
-
-
Save m-torin/1682947 to your computer and use it in GitHub Desktop.
Posts 2 Posts Programmatically Create Association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// begin front-end posting form | |
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&$_POST['action'] == "new_creditapp") { | |
$title =$_POST['title']; | |
$extracomments = $_POST['extracomments']; | |
$tags = $_POST['post_tags']; | |
$legalname = $_POST['legalname']; | |
// ADD THE FORM INPUT TO $new_creditapp ARRAY | |
$new_creditapp = array( | |
'post_title' => $title, | |
'post_content' => $extracomments, | |
'post_category' => array($_POST['cat']) ,// Usable for custom taxonomies too | |
'tags_input' => array($tags), | |
'post_status' => 'publish', // Choose: publish, preview, future, draft, etc. | |
'post_type' => 'creditapp', //'post',page' or use a custom post type if you want to | |
'legalname' => $legalname, | |
); | |
//SAVE THE POST | |
$pid = wp_insert_post($new_creditapp); | |
//SET OUR TAGS UP PROPERLY | |
wp_set_post_tags($pid, $_POST['post_tags']); | |
//REDIRECT TO THE NEW POST ON SAVE | |
$link = get_permalink( $pid ); | |
wp_redirect( $link ); | |
//ADD OUR CUSTOM FIELDS | |
add_post_meta($pid, '_dappdf_ca_legalname', $legalname, true); | |
// store post id of referring inventory | |
add_post_meta($pid, '_referringinventory', $referringinventory_postid, true); | |
// create connection | |
p2p_connect($pid, $referringinventory_postid); | |
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM | |
//POST THE POST YO | |
do_action('wp_insert_post', 'wp_insert_post'); | |
// finished with front-end posting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment