Hallo Zusammen,
ich arbeite derzeit an meinem ersten Plugin und verzweifle gerade etwas.
es dreht sich um eine Seite für die Vermietung von Ferienwohnungen.
Nun möchte ich einen eigenen Post-Type erstellen für spezielle Angebote.
Habe als erstes mal die Hauptdatei angelegt:
PHP
<?PHP/*Plugin Name: AngeboteDescription: Angebotsverwaltung für WordpressAuthor: Heiko PapenfußVersion: 1.0*/
setlocale(LC_ALL,'de_DE.UTF-8');
require_once('posttype.php');
require_once('datumsbox.php');
require_once('angebotsseite.php');
?>
Hier die Poststype.php
PHP
<?PHPadd_action('init','post_type_angebote');
function post_type_angebote(){ register_post_type ( 'angebote', array ( 'labels' => array ( 'name'=>'Angebote', 'singular_name'=>'Angebot', 'add_new_item'=>'Neues Angebot anlegen' ), 'public'=>true, 'show_ui'=>true, 'supports'=>array ( 'title','editor','thumbnail','custom-fields' ) ) );
}?>
und hier die Datumsbox.php
PHP
<?PHP
add_action('add_meta_boxes','angebote_addmetaboxes');add_Action('save_post','angebote_savedata');
function wohnungsauswahl_formular ($Wohnungsnummer, $variable_zum_pruefen){ if ( $variable_zum_pruefen == $Wohnungsnummer) { echo '<option value="'.$Wohnungsnummer.'" selected>Wohnung '."$Wohnungsnummer".'</option>'; } else { echo '<option value="'.$Wohnungsnummer.'" >Wohnung '."$Wohnungsnummer".'</option>'; } }
function angebote_addmetaboxes(){ add_meta_box ( 'angebote_metabox', 'Angebotsdaten', 'angebote_datumsbox', 'angebote', 'side', 'high' );
}
function angebote_datumsbox(){ wp_nonce_field('angebote_action','angebote_name'); echo '<div clas="angebot_von">'; echo '<p>Angebot von:</p>'; echo '<label for="angebot_plugin_form_1">Tag: </label>'; $tag=get_post_meta(get_the_ID(), '_tag',true); echo '<input type="number" step="1" min="1" max="31" size="2" maxlength="2" name="_tag" id="_tag" value="'.$tag.'" />'; echo '<label for="angebot_plugin_form_2">Monat: </label>'; $monat=get_post_meta(get_the_ID(), '_monat',true); echo '<input type="number" step="1" min="1" max="12" size="2" maxlength="2" name="_monat" id="_monat" value="'.$monat.'" />'; echo '<label for="angebot_plugin_form_3">Jahr: </label>'; $jahr=get_post_meta(get_the_ID(), '_jahr',true); echo '<input type="number" step="1" min="2014" max="2020" size="4" maxlength="4" name="_jahr" id="_jahr" value="'.$jahr.'" />'; echo '</div>'; echo '<div clas="angebot_bis">'; echo '<p>Angebot bis:</p>'; echo '<label for="angebot_plugin_form_4">Tag: </label>'; $tag1=get_post_meta(get_the_ID(), '_tag1',true); echo '<input type="number" step="1" min="1" max="31" size="2" maxlength="2" name="_tag1" id="_tag1" value="'.$tag1.'" />'; echo '<label for="angebot_plugin_form_5">Monat: </label>'; $monat1=get_post_meta(get_the_ID(), '_monat1',true); echo '<input type="number" step="1" min="1" max="12" size="2" maxlength="2" name="_monat1" id="_monat1" value="'.$monat1.'" />'; echo '<label for="angebot_plugin_form_6">Jahr: </label>'; $jahr1=get_post_meta(get_the_ID(), '_jahr1',true); echo '<input type="number" step="1" min="2014" max="2020" size="4" maxlength="4" name="_jahr1" id="_jahr1" value="'.$jahr1.'" />'; echo '</div>'; echo '<br />'; echo '<div clas="wohnungs-auswahl">'; $wohnungsauswahl=get_post_meta(get_the_ID(), '_wohnungsauswahl',true); echo '<select name="_wohnungsauswahl">'; wohnungsauswahl_formular ("1",$wohnungsauswahl); wohnungsauswahl_formular ("2",$wohnungsauswahl); wohnungsauswahl_formular ("3",$wohnungsauswahl); wohnungsauswahl_formular ("4",$wohnungsauswahl); wohnungsauswahl_formular ("5",$wohnungsauswahl); wohnungsauswahl_formular ("6",$wohnungsauswahl); wohnungsauswahl_formular ("7",$wohnungsauswahl); wohnungsauswahl_formular ("8",$wohnungsauswahl); wohnungsauswahl_formular ("9",$wohnungsauswahl); wohnungsauswahl_formular ("10",$wohnungsauswahl); echo '</select>'; echo '</div>'; $angebot_von=get_post_meta(get_the_ID(), '_zeitstempel_von',true); $angebot_bis=get_post_meta(get_the_ID(), '_zeitstempel_bis',true); echo date("d.m.Y",$angebot_bis);}
function angebote_savedata($post_id){ if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return false; if ( !current_user_can('edit_post',$post_id)) return false; if(!wp_verify_nonce($_POST['angebote_name'],'angebote_action')) return false;
update_post_meta($_POST['post_ID'],'_tag',$_POST['_tag'],false); update_post_meta($_POST['post_ID'],'_monat',$_POST['_monat'],false); update_post_meta($_POST['post_ID'],'_jahr',$_POST['_jahr'],false); update_post_meta($_POST['post_ID'],'_tag1',$_POST['_tag1'],false); update_post_meta($_POST['post_ID'],'_monat1',$_POST['_monat1'],false); update_post_meta($_POST['post_ID'],'_jahr1',$_POST['_jahr1'],false); update_post_meta($_POST['post_ID'],'_wohnungsauswahl',$_POST['_wohnungsauswahl'],false); $zeitstempel_von = mktime(0, 0, 0, $_POST['_monat'], $_POST['_tag'], $_POST['_jahr']); update_post_meta($_POST['post_ID'],'_zeitstempel_von',$zeitstempel_von,false); $zeitstempel_bis = mktime(0, 0, 0, $_POST['_monat1'], $_POST['_tag1'], $_POST['_jahr1']); update_post_meta($_POST['post_ID'],'_zeitstempel_bis',$zeitstempel_bis,false); }
?>
Alles anzeigen
nun besteht mein Problem in der angebotsseite.php hier der Code:
PHP
<?php
add_action('the_content','angebote_ansicht');
function angebote_ansicht( $content ){ if( get_post_type == 'angebote') return; $customs = get_post_custom (get_the_ID()); $wohnung = "Wohnung ".$customs['_wohnungsauswahl'][0]; return $content . $wohnung; }?>
Alles anzeigen
Ich wollte mit get_post_type abfragen ob es sich um ein 'Angebot' handelt.
Wenn ja dann die Aufgabe content modifizieren ansonsten den Content so ausgeben
aber irgendwie bekomme ich das nicht hin.
Weiss jemand warum ?