Advertisement
Guest User

Untitled

a guest
May 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package PostByMeta
  4.  * @version 1.0
  5.  */
  6. /*
  7. Plugin Name: PostByMeta
  8. Plugin URI: http://wordpress.org/plugins/hello-dolly/
  9. Description: Generate shortcode for posts by desired meta
  10. Author:remind
  11. Version: 1.0
  12. Author URI: null
  13. */
  14. add_action( 'admin_menu', 'postsbymeta_menu' );
  15. function pluginrender(){  // admin page bullshit
  16.     ?>
  17.     <div class="wrap">
  18.         <h2>Posts By Meta Settings</h2><br>
  19.         How many posts you like to display? <input type="text" disabled name="posts_count"><button>Set</button><br>
  20.         Enter Your Meta Name <input type="text" disabled name="meta_name"><br> 
  21.         Enter Match Value <input type="text" name="match_value" disabled>
  22.         <h4>Use Shortcode [poststoday] to render Posts</h4>
  23.  
  24.  
  25.     </div>
  26.     <?php
  27. }
  28. function postsbymeta_menu() { // adding menu
  29.     add_menu_page('PostsByMeta', 'PostsByMeta', 'manage_options', 'my-menu', 'pluginrender' );}
  30.  
  31.  function renderPosts() { // rendering posts
  32.     global $post;
  33. $args = array(
  34.  
  35.      'post_type' => 'post',
  36.      'meta_query'  => array(
  37.             array(
  38.                 'key' => 'date',
  39.                 'value' => date('d-m-Y')                        
  40.             )
  41.         )
  42.  
  43. );
  44. $lastposts = get_posts( $args );
  45. foreach ( $lastposts as $post ) :
  46.   setup_postdata( $post ); ?>
  47.     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  48.    
  49. <?php endforeach;
  50. wp_reset_postdata();
  51. }
  52. add_shortcode('poststoday','renderPosts');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement