Advertisement
jonahcoyote

Modified Custom Post Widget Query

Sep 26th, 2011
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. function widget($args, $instance) {
  2.         extract($args);
  3.         $custom_post_id  = ( $instance['custom_post_id'] != '' ) ? esc_attr($instance['custom_post_id']) : __('Find', 'custom-post-widget');
  4.         // Variables from the widget settings.
  5.         $show_custom_post_title = isset( $instance['show_custom_post_title'] ) ? $instance['show_custom_post_title'] : false;
  6.         //$content_post = get_post($custom_post_id);
  7.         $args = array(
  8.             'post_status'=>'publish',
  9.             'post_type'=>'content_block',
  10.             'p'=>$custom_post_id
  11.         );
  12.         $get_posts = null;
  13.         $get_posts = new WP_Query();
  14.        
  15.         $get_posts->query($args);
  16.         if ( $get_posts->have_posts() ) : while ( $get_posts->have_posts() ) : $get_posts->the_post();
  17.  
  18.             echo $before_widget;
  19.             if ( $show_custom_post_title ) {
  20.                 echo $before_title . get_the_title() . $after_title; // This is the line that displays the title (only if show title is set)
  21.             }
  22.             echo the_content(); // This is where the actual content of the custom post is being displayed
  23.        
  24.         echo $after_widget;
  25.        
  26.         endwhile; endif;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement