• Hi,

    I have written this simple widget. however when It comes to displaying the widget using the widget() I am finding the $instance not populated. Im pretty much pulling my hair out as this is quite simple, a second look would help please!

    ————————————–

    <?php
    
    /*
    Plugin Name: CV widget
    Plugin URI: NONE
    Description: Grabs and displays cv info based on content type
    Author: Dave Martin
    Version: 1
    Author URI:
    */
    
    class cvWidget extends WP_Widget
    {
    
    	function cvWidget()
    	{
    		$widget_options = array(
    			'classname' => 'cv-widget',
    			'description' => 'Daves CV widget');
    
    		parent::WP_Widget('cv_Widgeted','Daves CV Widget', $widget_options);
    
    	}
    
    	function form($instance){
    		?>
    		<label for="<?php echo $this -> get_field_id('title'); ?>">Name</label>
    		Title:
    		<input id="<?php echo $this -> get_field_id('title'); ?>"
    		name="<?php echo $this -> get_field_name('title'); ?>"
    		value="<?php echo $instance['title'];?>" />
    
    		<?php $post_types = get_post_types('', 'names');?>
    
    		<label for="posttype">Post Type:</label>
    		<select id="<?php echo $this -> get_field_id('posttype'); ?>"
    				name="<?php echo $this -> get_field_name('posttype'); ?>"
    
    			>
    		<?php
    		foreach ($post_types as $post_type) {
    			echo '<option value="'.$post_type.'"';
    			if ($instance['posttype'] == $post_type) {
    				echo 'selected="selected"';
    			}
    			echo'>' . $post_type . '</option>';
    		}
    		echo '</select>';
    		?>
    		<br/>
    		<label for="posttype">Ammount:</label>
    		<input id="<?php echo $this -> get_field_id('pullammount'); ?>"
    		name="<?php echo $this -> get_field_name('pullammount'); ?>"
    		value="<?php echo esc_attr($instance['pullammount'])?>" />
    
    		<?php	print_r($instance);
    	}
    
    	function widget($args,$instance){
    
    		print_r($instance); <-------HERE not populated (empty array)
    	}
    
    }
    
    	function cvWidget_init(){
    		register_widget("cvWidget");
    	}
    
    		add_action('widgets_init', 'cvWidget_init');

  • The topic ‘Wigdet() instance not populated?’ is closed to new replies.