Skip to content

Instantly share code, notes, and snippets.

@carfis
Last active August 29, 2015 14:16
Show Gist options
  • Save carfis/42069cac7cdcedc2afaf to your computer and use it in GitHub Desktop.
Save carfis/42069cac7cdcedc2afaf to your computer and use it in GitHub Desktop.
Funktion für ACF um ein Post in Frontend zu erzeugen
<?php
function videoproduzent_pre_save_post( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new' )
{
return $post_id;
}
// Create a new post
$post = array(
'post_status' => 'draft' ,
'post_title' => $_POST['acf']['field_5434172d1d00f'],
'post_type' => 'videoproduzenten' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// update custom Taxonomy (bundesland)
$terms = $_POST['acf']['field_5437aa29f0857'];
$terms = vo_bundesland_langeform($terms);
/*
if (!function_exists("preprint")) {
function preprint($s, $return=false) {
$x = "<pre>";
$x .= print_r($s, 1);
$x .= "</pre>";
if ($return) return $x;
else print $x;
}
}
preprint($terms);
die();
*/
wp_set_object_terms( $post_id, $terms, 'bundesland');
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'videoproduzent_pre_save_post' );
?>
<?php
function vo_bundesland_langeform($bundesland) {
switch( $bundesland ) {
case 'bw':
return 'Baden-Württemberg';
break;
case 'by':
return 'Bayern';
break;
case 'be':
return 'Berlin';
break;
case 'bb':
return 'Brandenburg';
break;
case 'hb':
return 'Bremen';
break;
case 'hh':
return 'Hamburg';
break;
case 'he':
return 'Hessen';
break;
case 'mv':
return 'Mecklenburg-Vorpommern';
break;
case 'ni':
return 'Niedersachsen';
break;
case 'nw':
return 'Nordrhein-Westfalen';
break;
case 'rp':
return 'Rheinland-Pfalz';
break;
case 'sl':
return 'Saarland';
break;
case 'sn':
return 'Sachsen';
break;
case 'st':
return 'Sachsen-Anhalt';
break;
case 'sh':
return 'Schleswig-Holstein';
break;
case 'th':
return 'Thüringen';
break;
}
}
?>
@carfis
Copy link
Author

carfis commented Mar 5, 2015

Ja so funktioniert mit return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment