WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a appointment plugin, and so far it is working that I can create appointments and see the detail view from the appointment.

The problem is, on a page called "appointments" where I wan't to list all appointments, nothing is displayed. I also would like to know, how I can modify the way all appointments are styled. I would like to have it placed in 4 columns.

I know the markup for this columns, but I don't know where I have to modify the plugin.

Here are the 5 files from my plugin:



 * Plugin Name: Termine
 * Description: Terminverwaltung für Wordpress
 * Author: Me
 * Version: 1.0

    setlocale(LC_ALL, 'de_DE.UTF-8');





    function post_type_termine(){


                'labels' => array(
                    'name' => 'Termine',
                    'singular_name' => 'Termin',
                    'add_new_item' => 'Neuen Termin anlegen'
                'public' => true,
                'show_ui' => true,

                'supports' => array(




datumsbox.php (used to place a box with appointment-details in the backend)




    function nw_termine_addmetaboxes(){

            'Datum und Ort',


    function termine_datumsbox(){

        wp_nonce_field('termine_action', 'termine_name');

        echo '<label for="myplugin_field1">Tag: </label>'; 
        $wert1=get_post_meta(get_the_ID(), '_tag',true);
        echo '<input type="number" step="1" min="1" max="31" id="myplugin_new_field" name="myplugin_field1" value="'.$wert1.'" style="width:4em"/>';

        echo '<label for="myplugin_field2">Mon.: </label>'; 
        $wert2=get_post_meta(get_the_ID(), '_monat',true);
        echo '<input type="number" step="1" min="1" max="12" id="myplugin_new_field2" name="myplugin_field2" value="'.$wert2.'" style="width:4em" />';  

        echo '<label for="myplugin_field3">Jahr: </label>'; 
        $wert3=get_post_meta(get_the_ID(), '_jahr',true);
        echo '<input type="number" step="1" min="2011" max="2020" id="myplugin_new_field3" name="myplugin_field3" value="'.$wert3.'" style="width:5em"/>';

        echo '<br/><label for="myplugin_field4">Stunde: </label>';
        $wert4=get_post_meta(get_the_ID(), '_stunde',true);
        echo '<input type="number" step="1" min="0" max="23" id="myplugin_new_field4" name="myplugin_field4" value="'.$wert4.'" style="width:4em"/>';  

        echo '<label for="myplugin_field5">Min.: </label>';
        $wert5=get_post_meta(get_the_ID(), '_minute',true);
        echo '<input type="number" step="1" min="00" max="59" id="myplugin_new_field5" name="myplugin_field5" value="'.$wert5.'" style="width:4em"/>';  

        echo '<br/><label for="myplugin_field7">Bis: </label>';
        $wert7=get_post_meta(get_the_ID(), '_bis',true);
        echo '<input type="text" id="myplugin_new_field7" name="myplugin_field7" value="'.$wert7.'" /> (beliebiger Text)';   

        echo '<br/><br/><label for="myplugin_field6">Adresse für Google Maps: </label><br/>'; 
        $wert6=get_post_meta(get_the_ID(), '_geo',true);
        echo '<input  id="myplugin_new_field6" name="myplugin_field6" value="'.$wert6.'" style="width:90%" />';   

        echo '<br/><br/><label for="myplugin_field8">Angezeigte Adresse: </label><br/>'; 
        $wert8=get_post_meta(get_the_ID(), '_geoanzeige',true);
        echo '<input  id="myplugin_new_field8" name="myplugin_field8" value="'.$wert8.'" style="width:90%" />';   


    function nw_termine_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['termine_name'],'termine_action') ) return false;

        update_post_meta($_POST['post_ID'], '_tag', $_POST['myplugin_field1'], false);
        update_post_meta($_POST['post_ID'], '_monat', $_POST['myplugin_field2'], false);
        update_post_meta($_POST['post_ID'], '_jahr', $_POST['myplugin_field3'], false);
        update_post_meta($_POST['post_ID'], '_stunde', $_POST['myplugin_field4'], false);
        update_post_meta($_POST['post_ID'], '_minute', $_POST['myplugin_field5'], false);
        update_post_meta($_POST['post_ID'], '_geo', $_POST['myplugin_field6'], false); 
        update_post_meta($_POST['post_ID'], '_bis', $_POST['myplugin_field7'], false);
        update_post_meta($_POST['post_ID'], '_geoanzeige', $_POST['myplugin_field8'], false);

        $zeitstempel=mktime((int) $_POST['myplugin_field4'],(int) $_POST['myplugin_field5'],0,(int) $_POST['myplugin_field2'],(int) $_POST['myplugin_field1'],(int) $_POST['myplugin_field3']);

        update_post_meta($_POST['post_ID'], '_zeitstempel', $zeitstempel, false);


termineansicht.php (detailview of an appointment)



    function nw_termine_ansicht( $content ){

        if ( get_post_type() != 'termine') return $content;

        $custom = get_post_custom (get_the_ID());

        $datumsformat = "%A, den %e. %B %G";

        $zeitanzeige = strftime($datumsformat,$custom['_zeitstempel'][0]);

            $zeitanzeige.=strftime(', um %H:%M Uhr',$custom['_zeitstempel'][0]);

        if(isset($custom['_bis'][0]) AND $custom['_bis'][0]!=''){
            $zeitanzeige .= ' bis '.$custom['_bis'][0];

        $datum='<div class="zeitanzeige" style="'.$options['style'].'">'.$zeitanzeige.'</div>';


        if(isset($custom['_geo']) AND $custom['_geo'][0]!=''){

            if(isset($custom['_geoanzeige'][0]) AND $custom['_geoanzeige'][0]!='') $adresse=$custom['_geoanzeige'][0];
            else $adresse=$custom['_geo'][0];

            $ort='<div class="googlemaps"><strong>Ort:</strong> '.$adresse;
            $ort.='<a href="https://maps.google.de/maps?q='.$geo.'" class="aufmapsanzeigen"><img src="http://maps.googleapis.com/maps/api/staticmap?center='.$geo.'&zoom=14&size=600x180&sensor=false&markers=color:green|'.$geo.'"/></a>';
            $ort.='<a href="https://maps.google.de/maps?q='.$geo.'" class="aufmapsanzeigen">Auf Google Maps anzeigen »</a>';

        return $datum . $content . $ort;



termine.php (a list of all appointments)


class terminadd{

    function rewrite_post($mypost){

        $mypost = stripslashes($mypost);


            $termininfo = "Termin";

            // Hole alle Termine    
            // die vergangen sind oder noch kommen  
                $order='DESC'; $compare='<';
                $title="Vergangene Termine";
                $order='ASC'; $compare='>=';
                $title="Kommende Termine";

            $posts = get_posts(
                        'orderby' => 'meta_value',
                        'meta_key' => '_zeitstempel',
                        'order' => $order,
                        'meta_query' => array(
                                    'key' => '_zeitstempel',
                                    'value' => time(),
                                    'compare' => $compare

            $termininfo = "$title ";    

            global $post;

            foreach ($posts AS $post){
                get_template_part( 'content', get_post_format() );


            $mypost = preg_replace("/\[termine\]/",ob_get_contents(),$mypost);


        return $mypost;


add_action('the_content', array(new terminadd(), 'rewrite_post'));

I've uploaded these files here:

appointment plugin download

share|improve this question

Generally, replacing content, especially with output buffering, is, at least in my mind, not very good practice. So you might consider making use of wordpress' templating system - see Codex: Templates for a start.

The former would also lead to, where your markup has to go. Or if you not using templates you have to write it into above files. Actually you are making use of templates already, with:

get_template_part( 'content', get_post_format() );

Which is looking for content-the-post-format.php, but shouldn't this be:

get_template_part( 'content', get_post_type() );

So you can create a template file content-the-post-type.php for that.

Additionally you are using $posts as variable name which is a global variable name used by wp, so this will lead to problems. Change the variable to a none-used/reserved name, generally, try using distinct and unique names to avoid conflicts. There is not need for the global $post; you are doing, you should also add wp_reset_postdata() to your code. Best you take another read of - at least - Codex: get_posts() to learn more yourself about how to do this.

These are just some pointers of course, but they should get you going into the right direction.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.