Support » Allgemeine Fragen » Adminbereich ausgabe nach datum sortieren

  • Wie bekomme ich es hin, das folgendes Plugin die Ausgabe im Adminbereich nach Datum sortiert.

    Die Ebooks erscheinen auch nicht im Monatsarchiv.

    <?php
    
    /*
    Plugin Name: MyBooks
    Description: Flash Magazine als neuen Post Typ anzeigen
    Author: Matthias
    Version: 0.0.2
    Author URI: http://www.wandernimsaaletal.de
    */
    
    /*  Copyright 2013  Matthias Reichert (email : matthias-reichert@mr-73.de)
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    add_action( 'init', 'create_post_type' );
    
    function create_post_type() {
    
    $labels = array(
    'name' => 'E-Books Einträge',
    'singular_name' => 'E-Books',
    'menu_name' => 'E-Books',
    'parent_item_colon' => '',
    'all_items' => 'Alle Einträge',
    'view_item' => 'Eintrag ansehen',
    'add_new_item' => 'Neuer Eintrag',
    'add_new' => 'Hinzufügen',
    'edit_item' => 'Eintrag bearbeiten',
    'update_item' => 'Update Eintrag',
    'search_items' => 'E-Books suchen',
    'not_found' => 'Kein E-Book gefunden',
    'not_found_in_trash' => '',
    );
    
    $rewrite = array(
    'slug' => 'book',
    'with_front' => true,
    'pages' => true,
    'feeds' => true,
    );
    
    $args = array(
        'labels' => $labels,
     	'public' => true, // Öffentlich zugänglich
    	'publicly_queryable' => true,
    	'show_ui' => true, // Im Administrationsbereich anzeigen
    	'show_in_menu' => true, // Im Menü anzeigen
    	'query_var' => true, // Für eigene Querys zugänglich machen
        'rewrite' => true,
        'capability_type' => 'post',
        'has_archive' => true,
        'hierarchical' => true,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail','excerpt','comments','customfields'),
    	'taxonomies' => array( 'category', 'post_tag' ), // add default post categories and tags
    	'public' => true,
    	'rewrite' => array('slug' => 'custom')
    );
    
    	register_post_type( 'book', $args );
    	register_taxonomy_for_object_type( 'category', 'book' );	
    
    }
    
    // hook into the init action and call create_book_taxonomies when it fires
    add_action( 'init', 'create_book_taxonomies', 0 );
    
    // create two taxonomies, genres and writers for the post type "book"
    function create_book_taxonomies() {
    
    	// Add new taxonomy, make it hierarchical (like categories)
    	$labels = array(
    		'name'              => _x( 'Regionen', 'taxonomy general name' ),
    		'singular_name'     => _x( 'Region', 'taxonomy singular name' ),
    		'search_items'      => __( 'Search Region' ),
    		'all_items'         => __( 'All Regionen' ),
    		'parent_item'       => __( 'Parent Region' ),
    		'parent_item_colon' => __( 'Parent Region:' ),
    		'edit_item'         => __( 'Edit Region' ),
    		'update_item'       => __( 'Update Region' ),
    		'add_new_item'      => __( 'Add New Region' ),
    		'new_item_name'     => __( 'New Region Name' ),
    		'menu_name'         => __( 'Region' ),
    	);
    
    	$args = array(
    		'hierarchical'      => true,
    		'labels'            => $labels,
    		'show_ui'           => true,
    		'show_admin_column' => true,
    		'query_var'         => true,
    		'rewrite'           => array( 'slug' => 'region' ),
    
    	);
    
    	register_taxonomy( 'region', array( 'book' ), $args );
    
    }
    
    /*
    # Artikel Suchen und anzeigen
    */
    
    add_filter( 'pre_get_posts', 'my_get_posts' );
    
    function my_get_posts( $query ) {
    
    	if ( is_home() && $query->is_main_query() )
    		$query->set( 'post_type', array( 'post', 'page', 'book', 'region' ) );
    
    	return $query;
    }
    
    function add_custom_types_to_tax( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    // Get all your post types
    $post_types = array( 'post', 'book' );
    
    $query->set( 'post_type', $post_types );
    return $query;
    }
    }
    add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );
    
    /*
     * Add Flash Magazine Metaboxes to book post-type
     *
     * http://codex.wordpress.org/Function_Reference/add_meta_box
     * http://blogs.sitepoint.com/guide-to-wordpress-custom-write-panels/
     */
    
    /**
     * Adds a box to the main column on the Book edit screens.
     */
    function book_add_custom_box() {
    
        $screens = array( 'book' );
    
        foreach ( $screens as $screen ) {
    
            add_meta_box(
                'book_sectionid',
                __( 'Flash Magazine Daten:', 'book_textdomain' ),
                'book_inner_custom_box',
                $screen
            );
        }
    }
    add_action( 'add_meta_boxes', 'book_add_custom_box' );
    
    /**
     * Prints the box content.
     *
     * @param WP_Post $post The object for the current post/page.
     */
    function book_inner_custom_box( $post ) {
    
      // Add an nonce field so we can check for it later.
      wp_nonce_field( 'book_inner_custom_box', 'book_inner_custom_box_nonce' );
    
      /*
       * Use get_post_meta() to retrieve an existing value
       * from the database and use the value for the form.
       */
    
      $value1 = get_post_meta( $post->ID, '_my_meta_value_key', true );
      echo '<label><b>Flash Magazin Link:</b><label>';
      echo '<br><input type="text" id="flashmagazin" name="flashmagazin" value="' . esc_attr( $value1 ) . '" size="75" /><br>';
    
      $value2 = get_post_meta( $post->ID, 'pdfurl', true );
      echo '<br><label><b>PDF Dokument Link:</b><label><br>';
      echo '<input type="text" id="pdfurl" name="pdfurl" value="' . esc_attr( $value2 ) . '" size="75" /><br><br>';
    
      echo '<label><b>I-Frame Link:</b><label><br>';
      $value3 = get_post_meta( $post->ID, 'artikelurl', true );
      echo '<input type="text" id="artikelurl" name="artikelurl" value="' . esc_attr( $value3 ) . '" size="75" /><br><br>';    
    
    }
    
    /**
     * When the post is saved, saves our custom data.
     *
     * @param int $post_id The ID of the post being saved.
     */
    function book_save_postdata( $post_id ) {
    
      /*
       * We need to verify this came from the our screen and with proper authorization,
       * because save_post can be triggered at other times.
       */
    
      // Check if our nonce is set.
      if ( ! isset( $_POST['book_inner_custom_box_nonce'] ) )
        return $post_id;
    
      $nonce = $_POST['book_inner_custom_box_nonce'];
    
      // Verify that the nonce is valid.
      if ( ! wp_verify_nonce( $nonce, 'book_inner_custom_box' ) )
          return $post_id;
    
      // If this is an autosave, our form has not been submitted, so we don't want to do anything.
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
          return $post_id;
    
      // Check the user's permissions.
      if ( 'book' == $_POST['post_type'] ) {
    
        if ( ! current_user_can( 'edit_page', $post_id ) )
            return $post_id;
    
      } else {
    
        if ( ! current_user_can( 'edit_post', $post_id ) )
            return $post_id;
      }
    
      /* OK, its safe for us to save the data now. */
    
      // Sanitize user input.
      $mydata1 = sanitize_text_field( $_POST['flashmagazin'] );
      $mydata2 = sanitize_text_field( $_POST['pdfurl'] );
      $mydata3 = sanitize_text_field( $_POST['artikelurl'] );
      $mydata4 = sanitize_text_field( $_POST['_store'] );
    
      // Update the meta field in the database.
      update_post_meta( $post_id, '_my_meta_value_key', $mydata1 );
    
      // Update the meta field in the database.
      update_post_meta( $post_id, 'pdfurl', $mydata2 );
    
      // Update the meta field in the database.
      update_post_meta( $post_id, 'artikelurl', $mydata3 );  
    
    }
    add_action( 'save_post', 'book_save_postdata' );
    
    ?>
Ansicht von 2 Antworten - 1 bis 2 (von insgesamt 2)
  • Thread-Ersteller maffylein

    (@maffylein)

    Hier ist noch der Link zur Seite!
    http://www.wandernimsaaletal.de/wanderfuehrer/

    Soweit funktioniert das Plugin recht gut.

    // eBooks im Back End nach Datum sortieren
    add_action('pre_get_posts', 'ebook_order_by_date');
    function ebook_order_by_date( $query ) {
      if (is_admin()) {
          // Get the post type from the query
          $post_type = $query->query['post_type'];
    
          if ( $post_type == 'book') {
            $query->set('orderby', 'date');
            $query->set('order', 'DESC'); // ggf. auf ASC ändern
          }
        }
    }
    
    // eBooks auch im Archiv anzeigen
    add_filter( 'pre_get_posts', 'ebook_archive' );
    function ebook_archive( $query ) {
    
    	if ( is_archive() && is_main_query() )
    		$query->set( 'post_type', array( 'post', 'page', 'book', 'region' ) );
    
    	return $query;
    }
    
    // ebBooks auch im Archiv-Widget berücksichtigen
    add_filter( 'getarchives_where', 'ebook_archive_widget' );
    function ebook_archive_widget( $where ){
        $where = str_replace( "post_type = 'post'", "post_type IN ( 'post', 'book' )", $where );
        return $where;
    }
Ansicht von 2 Antworten - 1 bis 2 (von insgesamt 2)
  • Das Thema „Adminbereich ausgabe nach datum sortieren“ ist für neue Antworten geschlossen.