[wp-hackers] Calling info from a Custom Field in a widget

Stephen Rider wp-hackers at striderweb.com
Sat Mar 29 02:19:58 GMT 2008


(Sorry if you get two copies of this.  I think the earlier one  
disappeared into the ether....)

Hi --

I'm trying to write a widget that calls text from a Custom Field on a  
page.  I'm using the Sandbox theme.  What I want is for the widget to  
display the custom field's content if present.  Here's what I have:

function widget_show_page_index($args) {
	extract($args);
	rewind_posts();
	if (have_posts()) : while (have_posts()) : the_post();
		if(get_post_custom_values('thisPageIndex')) {
			$toc_list = get_post_meta($post->ID, 'thisPageIndex', true);
			echo $before_widget;
			echo $before_title . 'On This Page' . $after_title;
			echo $toc_list}
			echo $after_widget;
		}
	endwhile; else:
		echo "<p>Nothing found.</p>";
	endif;
}

The "if (have_posts())" never returns True.  I've tried it with and  
without query_posts() -- makes no difference.  What am I missing here?

The "Not Found" shows up in the sidebar; so I know I'm at least  
calling the widget itself properly.  (That's just there for testing.)

Yes, I know I should preferably be using a new WP_Query object.  One  
thing at a time -- get it working then make it pretty... unless  
somebody has a snippet that will do it all in one go. :)

Thanks all,

Stephen


-- 
Stephen Rider
<http://striderweb.com/>




More information about the wp-hackers mailing list