Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @package PostByMeta
- * @version 1.0
- */
- /*
- Plugin Name: PostByMeta
- Plugin URI: http://wordpress.org/plugins/hello-dolly/
- Description: Generate shortcode for posts by desired meta
- Author:remind
- Version: 1.0
- Author URI: null
- */
- add_action( 'admin_menu', 'postsbymeta_menu' );
- function pluginrender(){ // admin page bullshit
- ?>
- <div class="wrap">
- <h2>Posts By Meta Settings</h2><br>
- How many posts you like to display? <input type="text" disabled name="posts_count"><button>Set</button><br>
- Enter Your Meta Name <input type="text" disabled name="meta_name"><br>
- Enter Match Value <input type="text" name="match_value" disabled>
- <h4>Use Shortcode [poststoday] to render Posts</h4>
- </div>
- <?php
- }
- function postsbymeta_menu() { // adding menu
- add_menu_page('PostsByMeta', 'PostsByMeta', 'manage_options', 'my-menu', 'pluginrender' );}
- function renderPosts() { // rendering posts
- global $post;
- $args = array(
- 'post_type' => 'post',
- 'meta_query' => array(
- array(
- 'key' => 'date',
- 'value' => date('d-m-Y')
- )
- )
- );
- $lastposts = get_posts( $args );
- foreach ( $lastposts as $post ) :
- setup_postdata( $post ); ?>
- <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
- <?php endforeach;
- wp_reset_postdata();
- }
- add_shortcode('poststoday','renderPosts');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement