Skip to content

Instantly share code, notes, and snippets.

@stankobrin
Created August 10, 2014 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stankobrin/975b24c7d7a780b82fc8 to your computer and use it in GitHub Desktop.
Save stankobrin/975b24c7d7a780b82fc8 to your computer and use it in GitHub Desktop.
apf_post_form
function apf_post_form()
{
?>
<form id="apfform" action="" method="post"enctype="multipart/form-data">
<div id="apf-text">
<input type="hidden" id="apflink" name="apflink" value="508"/>
<input type="hidden" id="apftitle" name="apftitle" value="SOI<?php the_ID();?>"/>
<input type="text" class="orderresult_qty" id="apfqty" name="apfqty"/>
<input type="hidden" id="apfdesc" name="apfdesc" value="<?php echo the_title() ;?>"/>
<input type="hidden" id="apfcode" name="apfcode" value="<?php echo the_field('style_code') ;?>"/>
<input type="hidden" class="orderresult_qty" id="apfprice" name="apfprice" value="<?php echo the_field('selling_price') ;?>"/>
<a class="button" id="addbutton" onclick="apfaddpost(apftitle.value,apfqty.value,apflink.value,apfcode.value,apfdesc.value,apfprice.value);" style="cursor: pointer">Add</a>
</div>
<div id="apf-response" style="background-color:#f4f0ed"></div>
</form>
<?php
}
function apf_addpost() {
$results = '';
$title = $_POST['apftitle'];
$orderqty = $_POST['apfqty'];
$orderlink = $_POST['apflink'];
$ordercode = $_POST['apfcode'];
$orderdesc = $_POST['apfdesc'];
$orderprice = $_POST['apfprice'];
$post_id = wp_insert_post( array(
'post_type' => 'order-items',
'post_author' => $user->ID,
'post_title' => $title,
'post_status' => 'publish'
) );
add_post_meta($post_id, 'product_code', $ordercode, true);
add_post_meta($post_id, 'product_description', $orderdesc, true);
add_post_meta($post_id, 'quantity', $orderqty, true);
add_post_meta($post_id, 'unit_price', $orderprice, true);
if ( $post_id != 0 )
{
$results = '*Item added to favourites';
}
else {
$results = '*Error occurred while adding the item';
}
// Return the String
die($results);
}
// creating Ajax call for WordPress
add_action( 'wp_ajax_nopriv_apf_addpost', 'apf_addpost' );
add_action( 'wp_ajax_apf_addpost', 'apf_addpost' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment